You are here: Re: Diff Between 2 Dates « PHP Programming Language « IT news, forums, messages
Re: Diff Between 2 Dates

Posted by Chung Leong on 10/24/16 11:41

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация