Alright, I have 2 dates.
They first is written like this:
02/03/04
and the second is todays' date:
01/07/10.
Now I wonder, can anyone help me with a script that calculates how many days it has gone (days, not months or weeks) since the first date to the second?
I would be so grateful.
Thanks.
Days since date
Moderator: General Moderators
Re: Days since date
i want to do it in php, not sql.
Thanks for quick answer.
Thanks for quick answer.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Days since date
Those dates won't be handled correctly by strtotime(), so something like this:
You can use abs() on the result if the start date can be greater than the end date. Also, you can use round(), ceil() or floor() to round the days as appropriate.
Code: Select all
$start = explode('/', '02/03/04');
$end = explode('/', '01/07/10');
$days = (mktime(0,0,0,$end[1],$end[0],$end[2]) - mktime(0,0,0,$start[1],$start[0],$start[2])) / 86400; //60sec * 60min * 24hrs mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.