PDA

View Full Version : Date function ???


marquito
09-27-04, 03:14 PM
Hello. I'm not sure how to start this.

My program is returning a DATE --> CVALUE

Now what I need is to make sure that this value is always a SATURDAY. Therefore I need to increase or decrease the date

****
WED | THUR | FRI | SAT | SUN | MON | TUE

incrase to SATURDAY decrease to SATURDAY
------------------> <------------------


Explanation:
if it is Wed | Thu | Fri ---> increase to Saturday
if it is Sun | Mon | Tues ---> decrease to Saturday.


Anybody wrote a function like this ? HELP would be very appreciated.

Thank you

marco

Naresh Rohra
10-01-04, 06:22 PM
Hi there,

Hope this helps.

I don't have time to code but i hope following algorithm might help u.

First find the current day. say Thursday For that
I know on 01/01/0001 it was monday so the calculation will be.
DaysPassed = 365 * (currentyear - 1) + NumberOfDaysPassedThisYear + LeapYearDays
so today day will be: Today = DaysPassed mod 7
this will give u integer within value 0 to 6. So create array of string store all days in it with monday being the first element. Use the Today value as index and u will find the day.

Now to go to saturday (which will be at 5th index position)

check if Today is > 6, 0, 1 then
subtract u will have to do subtraction of Today from Date value which are u getting u specified.


I think this broken :D algorithm will help with little logic for u to implement.

Yeah.....about LeapYearDays

U can use code as


intCurrentYear = 2004
intLeapDays = 0
for intCountYear = 1 to intCurrentYear
If intCountYear mod 4 = 0 And intCountYear mod 100 != 0 Or intCountYear mod 400 = 0 Then
intLeapDays += 1
next



Else check if there is any function in DateTime class which returns Day string for todays Date, then u will save ur calculation part.
Cheers.
Naresh.