Thread: days between dates formula

  1. #1

    days between dates formula

    how can I calculate the number of days between two dates?
    I found some programs on the internet that do it but none gave me the formula on how it works .

    if it makes it any simpler, I'm using php (maybe with build in functions)

    thx

    --Maes

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    ...that's just simple addition and subtraction...unless there is something i dont understand here...

    Days between Jan 5th and April 7th:

    NumDaysJan() + NumDaysFeb() + NumDaysMarch() + 7 - 5

    P.S. those are not real functions...that's pseudocode...
    My Website

    "Circular logic is good because it is."

  3. #3
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Find number of elapsed years
    Multiply the number of days in a year times the number of elapsed years
    add 1 day to that number per leap year in elapsed years
    find number of elapsed months (not included in elapsed years)
    add all the days of those elapsed months
    find the number of elapsed days in the month (not included in elapsed months)
    violla.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  4. #4
    Oh man I'm o embarresed

    I read something on the internet about julian days.
    actualy found a fromula that was about a page in length and stuff like that so I thought there would be a catch somwhere.
    I kept thinking with hunderd of years between the dates that I didn't see it was that simple

    thx DavidP & db_goten

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    No... Dates are terribly hideous to work with. There is an example in Numerical Recipes that gets the Julian Day Number given a calendar date.
    http://lib-www.lanl.gov/numerical/bookcpdf.html
    It is section 1.1, starting on the 7th page. The function is 'julday'

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting days between 2 dates
    By nynicue in forum C Programming
    Replies: 12
    Last Post: 02-19-2010, 10:50 AM
  2. how can i get the number of days between two dates?
    By acohrockz21 in forum C Programming
    Replies: 3
    Last Post: 02-29-2008, 10:43 AM
  3. number of days between 2 dates.
    By explosive in forum C++ Programming
    Replies: 10
    Last Post: 02-17-2005, 07:30 AM
  4. C++ number of days between 2 dates?
    By Rain1522 in forum C++ Programming
    Replies: 1
    Last Post: 03-13-2002, 09:09 PM
  5. Calculating days between two Dates
    By Niy in forum C++ Programming
    Replies: 9
    Last Post: 03-12-2002, 08:16 PM