Connecting Tech Pros Worldwide Help | Site Map

Diff Between 2 Dates

  #1  
Old March 4th, 2006, 03:15 AM
Mike
Guest
 
Posts: n/a
I am trying to find the difference between 2 dates. The problem that I am having is that all
routines in the PHP Manual and all of the scripts I have seen on the Internet only allow a date as
old as 1970. I am trying to find the age of a person in months so 1970 is not far back enough. Does
anyone know of a script where 1970 is not a restriction?

Thanks in advance.

Mike


  #2  
Old March 4th, 2006, 06:35 AM
Carl Vondrick
Guest
 
Posts: n/a

re: Diff Between 2 Dates


Mike wrote:[color=blue]
> I am trying to find the difference between 2 dates. The problem that I am having is that all
> routines in the PHP Manual and all of the scripts I have seen on the Internet only allow a date as
> old as 1970. I am trying to find the age of a person in months so 1970 is not far back enough. Does
> anyone know of a script where 1970 is not a restriction?
>
> Thanks in advance.
>
> Mike
>
>[/color]
Does the server run Linux or Windows?

--
Carl Vondrick
www.carlsoft.net
usenet [at] carlsoft [dot] net
  #3  
Old March 4th, 2006, 08:35 AM
Janwillem Borleffs
Guest
 
Posts: n/a

re: Diff Between 2 Dates


Mike wrote:[color=blue]
> I am trying to find the difference between 2 dates. The problem that
> I am having is that all routines in the PHP Manual and all of the
> scripts I have seen on the Internet only allow a date as old as 1970.
> I am trying to find the age of a person in months so 1970 is not far
> back enough. Does anyone know of a script where 1970 is not a
> restriction?
>[/color]

Have a look at the calendar extension:

http://www.php.net/calendar


JW


  #4  
Old March 4th, 2006, 04:45 PM
Chung Leong
Guest
 
Posts: n/a

re: Diff Between 2 Dates



Mike wrote:[color=blue]
> I am trying to find the difference between 2 dates. The problem that I am having is that all
> routines in the PHP Manual and all of the scripts I have seen on the Internet only allow a date as
> old as 1970. I am trying to find the age of a person in months so 1970 is not far back enough. Does
> anyone know of a script where 1970 is not a restriction?
>
> Thanks in advance.
>
> Mike[/color]

The solution is quite simple. This is how people do it in their heads.
First, substract the year the person is born from the current year.
Then, check whether the person has already celebrated his/her birthday
this year. If not--substract one.

Here's an implementation:

function age($year, $month, $day) {
$now_ts = time();
$now_a = getdate($now_ts);
$age = $now_a['year'] - $year;
$bday_ts = mktime(0, 0, 0, $month, $day, $now_a['year']);
if($now_ts < $bday_ts) {
$age--;
}
return $age;
}

  #5  
Old March 4th, 2006, 07:25 PM
Richard Levasseur
Guest
 
Posts: n/a

re: Diff Between 2 Dates


Be aware this works fine for someone's age, but for more precise date
calculations, especially at much older/earlier dates, you will have to
account for all the funny time changes, corrections, and drift that
have taken place (like how they skipped a couple days completely to
make up for lost time). So i would suggest either reading up on
date/time calculations extensively or finding a good preexisting library

  #6  
Old March 4th, 2006, 10:25 PM
Gordon Burditt
Guest
 
Posts: n/a

re: Diff Between 2 Dates


>I am trying to find the difference between 2 dates. The problem that I[color=blue]
>am having is that all
>routines in the PHP Manual and all of the scripts I have seen on the
>Internet only allow a date as
>old as 1970. I am trying to find the age of a person in months so 1970
>is not far back enough. Does
>anyone know of a script where 1970 is not a restriction?[/color]

PHP suffers from the limitations of a UNIX time_t. I recommend
using MySQL date functions where the allowed range includes the
years 1 thru 9999, which is good enough for most practical uses.

Gordon L. Burditt
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Days Between Dates sha2484 answers 9 November 10th, 2008 12:34 PM
With a table of holidays and A97's date fn's - how best to count weekends and holidays between two dates MLH answers 2 September 25th, 2006 01:55 PM
Date diff help please,in c# Raghu Raman answers 3 November 18th, 2005 08:54 PM
datetime: How to get diff between 2 dates in month units? python@sarcastic-horse.com answers 0 July 18th, 2005 03:33 AM