Page 1 of 1

calculate a week

Posted: Thu Oct 22, 2015 8:46 am
by Silvio.Falconi
Dear Friends,

I have a date sample 16.10.2015

I wish Know the week where there is this date

sample : from 12.10.2015 to 17.10.2015


exist a function give me this ?

thanks in advance
I need this because I must calculate how many times a teacher is on a specific classroom

Re: calculate a week

Posted: Thu Oct 22, 2015 10:18 am
by driessen
The DOW() function?

Re: calculate a week

Posted: Thu Oct 22, 2015 10:46 am
by Silvio.Falconi
Sorry,
DOW() returns the day of the week as a number between zero and seven.

I want the function return me the date of first day of the week and the date of the seven day of the week of the date past

sample if I have 16.10.2015 -----> give me 12.10.2015 and 18.10.2015

I hope you undestood me

Re: calculate a week

Posted: Thu Oct 22, 2015 11:22 am
by driessen
Yes, that's right. But by using the function DOW(), you can get your goal like this :

Code: Select all

FUNCTION FirstLastDOW(dDate)

   LOCAL cDow   := DOW(dDate) // 1 = Sunday / 2 = Monday / ... / 7 = Saturday
   LOCAL cFDate               // last Monday before dDate
   LOCAL cLDate               // first sunday after dDate

   cFDate = IF( cDow = 1, dDate - 6 , IF( cDow = 2, dDate, dDate - ( cDow - 2 ) ) )
   cLDate = IF( cDow = 1, dDate, dDate + ( 8 - cDow ) )
   
RETURN({cFDate,cLDate})
Good luck !!!

Re: calculate a week

Posted: Thu Oct 22, 2015 11:26 am
by zekasan
wom(date()), i read your post now

Re: calculate a week

Posted: Thu Oct 22, 2015 11:40 am
by Silvio.Falconi
FirstLastDOW(dDate) RUN GOOD ONLY
in Italy we have the first day monday and the six saturday ( seven sunday)