Problem with date functions

Just starting out? Need help? Post your questions and find answers here.
Gantry
User
User
Posts: 20
Joined: Tue Jun 03, 2003 6:24 am
Location: Sweden

Problem with date functions

Post 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
*** In the end we will remember not the words of our enemies, but the silence of our friends. (Martin Luther King Jr.) ***
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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?
Gantry
User
User
Posts: 20
Joined: Tue Jun 03, 2003 6:24 am
Location: Sweden

Post 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
*** In the end we will remember not the words of our enemies, but the silence of our friends. (Martin Luther King Jr.) ***
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Yes, I see the same strangeness here with XP and PB 3.71 Beta 2..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
CoderLaureate
User
User
Posts: 50
Joined: Fri Apr 25, 2003 7:21 pm
Location: The World is my country, all mankind are my brethren, and to do good is my religion.
Contact:

A work around.

Post 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
Gantry
User
User
Posts: 20
Joined: Tue Jun 03, 2003 6:24 am
Location: Sweden

Post 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
*** In the end we will remember not the words of our enemies, but the silence of our friends. (Martin Luther King Jr.) ***
Post Reply