CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    36

    working with time

    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

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    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.
    Succinct is verbose for terse

  3. #3
    Join Date
    May 2004
    Location
    Cracow - Poland (Europe)
    Posts
    59
    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...
    Sorry for my poor English language skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured