Click to See Complete Forum and Search --> : working with time


zariostr
May 18th, 2004, 12:52 PM
hello
i trying to process time data for example i have
"zero point"
23.11.2004 12:34:45
d m y h m s

and i got value like that
11 days 20 hours 34 minutes 59 seconds

how correct ADD this value to "zero point" and as result get right date ???

also i intresting how get and using leap years ?


P.S. I'm using MSVC (WinAPI without MFC)

thanks

cup
May 20th, 2004, 01:59 AM
Look up Zeller's Congruence on the net. There are basically 2 formulas: one for day of the week and another for an absolute unique number for every day. You want the latter, which is a variant of the original. Convert your date to these absolute numbers, multiply by 86400 add in the time and then do the reverse to get back the new date/time.

The reverse formula may need one or two iterations.

Yansen
May 20th, 2004, 07:33 AM
Best way - as I think - is usage of numerical recipies function JULDAY (Julian Day number from calendar date). So you get a number of day since January 1st, 4713 B.C. (it's long int). Bonus is you can add to date, substract to date (is simple numers add's and substraction..) and you don't have a head splitting. If you don't have NR search the net with "Julian Day" you probably will obtain:
http://www.hermetic.ch/cal_stud/jdn.htm

Bileve me - changing date's to Julian Day substract it (or add) is 3x beter method...