calculating sun(first)day of the week

I want to calculate by a method the first day of the week (Sunday)

For example if today is 19-06-2003 I want the result back: 15-06-2003(past sunday)

In Filemaker you can do this by setting a field:

Status(CurrentDate) - (DayofWeek(Status(CurrentDate)) -1)

Anyone can help me with this?

Always tought monday was the first day of the week :wink:
That’s why I’m glad in Servoy monday is the first of the week by default unlike Filemaker where sunday is the first day of the week by default and alway’s have (had) to make a workaround with the calculation you mentioned.

It depends! In bible-terms (christian), sunday is the first the day of the week. In other database and program’s monday is the first day of the week!

Does anyone know the method?

I tried with this method and seems to work:

var a = yourdate;
a.setDate(a.getDate() - a.getDay());

in a you obtain the desidred sunday.
getday() gives you 0 on sunday… 6 on saturday

hope this helps

What the first day of the week is depends on youre locale setting (see preferences and then locale tab)
If yours are dutch/NL then Monday is first day of week, if however it is set to USA then Sunday is first day of week.

If you want to know what the first day is in your scripts you can check with the util.isMondayFirstDayOfWeek() (1.1 release)

With that value (true/false) you can write your scripts.

(Don’t make scripts that just thinks it starts on sunday or monday!
Because those scripts are made to fail!) ;-)

Hi date-specialists…

Q1: I want to get the full year of a date in field1
field1: date_input
field2: date_calc [calculation / stored / INT]:

var a=date_input;
a.setYear(a.getYear())
return a;

Q2: The full year of today (in FMP: Year(Today))

Q1: I want to get the full year of a date in field1
field1: date_input
field2: date_calc [calculation / stored / INT]:

date_calc > return date_input.getFullYear()

Q2: The full year of today (in FMP: Year(Today))

var today = new Date()
return today.getFullYear()

OR

return new Date().getFullYear()

(new Date() creates a date object with current timestamp)

Thanks Maarten.

Ronald

jcompagner wrote:

What the first day of the week is depends on youre locale setting (see preferences and then locale tab)
If yours are dutch/NL then Monday is first day of week, if however it is set to USA then Sunday is first day of week.

what automazione suggests isnM-4t right then. My local/settings are Dutch=NL The calculation returns still Sunday.

What is the right calculation to get the first day of the week? (dependly what my localsetting are?)

Hi,

javascript .getday() returns 0 for sunday, 1 for monday.. 6 for saturday.

So if you want the sunday before your date

var a = yourdate;
a.setDate(a.getDate() - a.getDay());

should work and if you want monday …

a.setDate(a.getDate() - a.getDay() + 1);

and this is independent of the “locale settings”
but if you want the calculated date to depend on your “locale setting” you can test

if (util.isMondayFirstDayOfWeek())
{
a.setDate(a.getDate() - a.getDay() + 1);
}
else
{
a.setDate(a.getDate() - a.getDay());
}

hope this helps (and also hope it’s correct), bye

Enrico

HJK:

Where do you set youre default locale? Do you mean in windows or mac?

In servoy you can also set youre locale in the preferences->locale tab.

If i have here Dutch then this script:
application.output(utils.isMondayFirstDayOfWeek())

outputs true

if i change it to englisch/usa then it returns false

i test this against RC4

in Servoy preferences->locale

1.1 rc4 w2k