Categories
Snaps
Search
Register
Contact
API
Number of days between two dates
Returns the actual number of days between two specific dates
// Will return the number of days between the two dates passed in function count_days( $a, $b ){ // First we need to break these dates into their constituent parts: $a = strtotime( $a . " 8:00am" ); $b = strtotime( $b . " 8:00am" ); $gd_a = getdate( $a ); $gd_b = getdate( $b ); /** Now recreate these timestamps, based upon noon on each day **/ The specific time doesn't matter but it must be the same each day $a_new = mktime( 12, 0, 0, $gd_a['mon'], $gd_a['mday'], $gd_a['year'] ); $b_new = mktime( 12, 0, 0, $gd_b['mon'], $gd_b['mday'], $gd_b['year'] ); /** Subtract these two numbers and divide by the number of seconds in a * day. Round the result since crossing over a daylight savings time **/ barrier will cause this time to be off by an hour or two. return round( ($a_new - $b_new ) / 86400 ); }
Usage
Comments
Add your comment
Search
Coder: JoeByrne
View more snaps from JoeByrne
View JoeByrne's profile
Rate this snap
Rating:
0
/ 5 (
0
votes) 1070 views
Custom class generator
Selected snaps:
None selected yet.
Hot PHP snaps
PHP image slideshow auto
PHP pagination class
Bootstrap PHP code
Clean URL
PHP ffmpeg Upload Script
Rijndael 256 bit encryption using mcrypt
generate a preview image from an FLV file on-the-fly, or to save
Median calculator
Partners
PHP Site
PHPSnips
Comments