Category: >> PHP Code >> Calculate days between any two dates Bookmark and Share

<< lastnext >>

Snippet Name: Calculate days between any two dates

Description: A simple way to calculate the number of days between two dates using almost any typical date format (MM-DD-YYYY or YYYY-MM-DD, etc).

Also see:
» Time left In Weeks, Days, Hours, A...
» Get Relative Dates and Times
» Convert UK Dates To mySQL Format D...
» Calculate the difference between t...
» Dates: Oddball Stuff
» Date Functions: Calculate elapsed ...
» Date/Time Calculations: Get second...
» Date Functions: Add and Subtract f...
» Calculate date of Easter Sunday
» Add and Subtract dates
» Select or match a range of dates
» Calculate TIMEDIFF with mysql vers...
» Calculate Pi
» Calculate time difference between ...
» Number Functions: Calculate ratio ...
» Count days between dates
» Find days between dates #1
» Calculate Zipcode Distances
» Calculate Distance From Latitude a...
» Calculate File/Folder Size In A Di...

Comment: (none)

Author: SmithyGotLost
Language: PHP
Highlight Mode: PHP
Last Modified: March 03rd, 2012

// simple way to calculate days between two dates
// using abs() prevents negative dates
$from = strtotime($from);
$to = strtotime($to);
$datediff = abs($to - $from);
echo floor($datediff/(60*60*24));
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 12