Diff Between 2 Dates

This is a discussion on Diff Between 2 Dates within the PHP Language forums, part of the PHP Programming Forums category; I am trying to find the difference between 2 dates. The problem that I am having is that all routines ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-04-2006
Mike
 
Posts: n/a
Default Diff Between 2 Dates

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


Reply With Quote
  #2 (permalink)  
Old 03-04-2006
Carl Vondrick
 
Posts: n/a
Default Re: Diff Between 2 Dates

Mike wrote:
> 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
>
>

Does the server run Linux or Windows?

--
Carl Vondrick
www.carlsoft.net
usenet [at] carlsoft [dot] net
Reply With Quote
  #3 (permalink)  
Old 03-04-2006
Janwillem Borleffs
 
Posts: n/a
Default Re: Diff Between 2 Dates

Mike wrote:
> 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?
>


Have a look at the calendar extension:

http://www.php.net/calendar


JW


Reply With Quote
  #4 (permalink)  
Old 03-04-2006
Chung Leong
 
Posts: n/a
Default Re: Diff Between 2 Dates


Mike wrote:
> 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


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;
}

Reply With Quote
  #5 (permalink)  
Old 03-04-2006
Richard Levasseur
 
Posts: n/a
Default 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

Reply With Quote
  #6 (permalink)  
Old 03-04-2006
Gordon Burditt
 
Posts: n/a
Default Re: Diff Between 2 Dates

>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?


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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:19 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0