PHP Date Difference


This script calculates the days between two given dates.

function timeDiff($firstTime,$lastTime) {
	// convert to unix timestamps
	$firstTime = strtotime($firstTime);
	$lastTime = strtotime($lastTime);
	// perform subtraction to get the difference (in seconds) between times
	$timeDiff = ( $lastTime - $firstTime );
	// return the difference
	return $timeDiff;

// two dates
$date = strtotime("2012-01-01");
$date2 = strtotime("2012-02-01");

// get the difference
$diff = $timeDiff=($date2-$date)/60/60/24;

// echo difference
echo $diff;


Related articles

Redirect www to non www with .htaccess RewriteRule

Redirect www to non www with .htaccess RewriteRule


Redirect your websites visitors from to without www.

Email Validation

Email Validation


Learn how to validate email on client side with HTML5, Javascript and on server side with PHP.

Generate Thumbnail on the Fly with PHP

Generate Thumbnail on the Fly with PHP


In a previous artice I already showed you how to generate square thumbnails with PHP. Now I show you how to keep the original ratio of the image and how to control the alignment of the square image.

Leave a comment

We welcome any comment from you! Please keep in mind that comments are moderated and rel='nofollow' is in use. So, please do not use a domain as your name or a spammy keyword, or your comment will be deleted.

Name: *

E-mail: *

Message: *

Click on the flower *

Find us on Facebook



Back to Top