Reply to Re: Date functions Months / Years Months between two dates.

Your name:

Reply:


Posted by severin on 06/24/07 19:56

Rob wrote:
> Just hoping that that someone in this group would have some date
> functions they might be prepared to share.
>
> 1. Number of Months between two dates
>
> 2. Number of Years/ Months two dates
>
> Either of these would be good.

The most efficient way to control date and time is the timestamp.
(numbers of microseconds since 1/1/1970, not very good for birthday
before 1970!!)

storing date like string('Year/month/day') is not easy to work with.

If u store dates in a database, use timestamp
(type of colomn: interger(14) , the "timestamp" type doesn't work well
as far as i know.)


you timestamp is like : 32165487451232
to create a timestamp:
$mydate=mktime("hour,min,sec,Year,month,day")
$today = mktime();(including hour,min,sec...)
-> see php doc search timestamp

Your date is:
<? echo date("Y m d",32165487451232) ?>
returns: Year Month Day of your timestamp.
<? echo date("Y/m/d",32165487451232) ?>
returns: Year/Month/Day of your timestamp.
Many option accessible including the name of the day at any given date.
-> phpdoc search date


and now all operation are easy:

you have $timestmp1, $timestmp2
make sure $timestamp2 > timestamp1...


Number of Months between two dates:

echo (
date("m",$timestamp2) - date( "m", $timestamp1) +
(date("Y",$timestamp2) - date( "Y", $timestamp1)) *12)
)
...

no future without timestamp.

[Back to original 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

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