calculate a week

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

calculate a week

Post 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
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: calculate a week

Post by driessen »

The DOW() function?
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: calculate a week

Post 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
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: calculate a week

Post 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 !!!
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
zekasan
Posts: 7
Joined: Fri Feb 22, 2008 12:11 pm

Re: calculate a week

Post by zekasan »

wom(date()), i read your post now
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: calculate a week

Post by Silvio.Falconi »

FirstLastDOW(dDate) RUN GOOD ONLY
in Italy we have the first day monday and the six saturday ( seven sunday)
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply