Page 1 of 1

Problem with date functions

Posted: Mon Jul 07, 2003 9:00 pm
by Gantry
newdate=Date(1998,12,12,14,22,36)
Debug FormatDate("%yyyy %mm %dd %hh %ii %ss",newdate)
newdate=AddDate(newdate,#PB_Date_Year,0)
newdate=AddDate(newdate,#PB_Date_Month,0)
newdate=AddDate(newdate,#PB_Date_Day,0)
newdate=AddDate(newdate,#PB_Date_Hour,0)
newdate=AddDate(newdate,#PB_Date_Minute,0)
newdate=AddDate(newdate,#PB_Date_Second,0)
Debug FormatDate("%yyyy %mm %dd %hh %ii %ss",newdate)

What is wrong with this code? I don't add anything to the date and still it is not the same before and after the operations?

Regards,

Gantry

Posted: Mon Jul 07, 2003 9:11 pm
by Pupil
Weird, further investigation reveals that these two line subtracts one hour each from the date:

Code: Select all

; ...
newdate=AddDate(newdate,#PB_Date_Year,0)
newdate=AddDate(newdate,#PB_Date_Month,0)
; ...
Maybe you should post this in bug section on this forum instead?

Posted: Mon Jul 07, 2003 9:16 pm
by Gantry
:cry:
Well, yes maybe it is a bug. I wasn't sure until someone else tried it. I will post it in the bugs section as well. Thank you for confirming my findings!

/Gantry

Posted: Mon Jul 07, 2003 10:34 pm
by Karbon
Yes, I see the same strangeness here with XP and PB 3.71 Beta 2..

A work around.

Posted: Tue Jul 08, 2003 1:40 am
by CoderLaureate
I ran into this problem a little while ago too.
I didn't know if it was a bug, or I was doing something wrong.

As a work around, I just did all date math in the form of seconds.
You may well know that the Date() function returns a Long integer containing the date in seconds. In order to do any date math you can simply add/subtract the amount in seconds.

I.E.

Code: Select all

NewDate.l = Date(1998,12,12,14,22,36)
Debug FormatDate("%yyyy %mm %dd %hh %ii %ss",NewDate)

;Add One Day to New Date
NewDate + (3600 * 24); 3600 seconds in one hour * 24 hours
Debug "One Day Later: " + FormatDate("%yyyy %mm %dd %hh %ii %ss",NewDate)

;Add One Week to New Date
NewDate + (86400 * 7); 86400 seconds in one day * 7 days
Debug "One Week Later: " + FormatDate("%yyyy %mm %dd %hh %ii %ss",NewDate)

Hope this helps with your problem until Fred can get this bug nailed down.

-Jim

Posted: Tue Jul 08, 2003 9:05 am
by Gantry
I guess seconds will do the trick just as well, and hopefully better. :wink:


I will try it when I get home from work,

/Gantry