Could use some help for DateAdd() function

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.

Hi all,

I like to create a DateAdd function in PB, to do this...

Code: Select all

k = PeekL(@buffer$ + 22)  ; k = number of seconds past since 01/01/1970 00:00:00 hour
LogDate = DateAdd("s", k, "01.01.1970")   ; ad the seconds in k to 1970 and calculate the date k is representing
So, just add the seconds in k to 01/01/1970 and calculate the date and time again.

Adding k is easy...and calculating the days and time also...
This is the start

Code: Select all

Procedure MyMod(a,b)
  ProcedureReturn a - (a/b)*b
EndProcedure

timestring.s="23:26:58"  ; starttime in string
Debug "StartTime: "+ timestring
timevalue=Val(Left(timestring,2)) * 3600 
timevalue + Val(Mid(timestring,4,2)) * 60 
timevalue + Val(Right(timestring,2)) 

Debug "StartTime in Seconds: "+Str(timevalue)    ; starttime in seconds

k=902314
Debug "Add "+ Str(k) + " seconds To time, about "+Str(k/60)+" minutes"
timevalue + k
a$= Using("00",timevalue / 3600 /24) + " days,  time: "        ; days
a$ + Using("00",MyMod(timevalue / 3600,24)) + ":"  ; hours
a$ + Using("00",MyMod(timevalue / 60,  60)) + ":"  ; minutes 
a$ + Using("00",MyMod(timevalue,60))               ; seconds 

Debug a$

; Note: Not using Imod in Mathextras for OS independence
; Note: using() from Mr Skunks library just for display purposes
Anybody know's how to get the date out of the number of days?




Regards,

Benny

http://www.benny.zeb.be