Whistles

geekery and stuff

PHP to calculate date/time differences

View Comments

Here is a PHP code snippet that can be used to calculate time difference between two dates:

$post_date_str1 = the_date('Y-m-dTH:i:s', '', '', false); 
$post_date1 = new Date($post_date_str1); 
$birth_date1 = new Date("1979-07-15T18:00:00"); 
$span1 = new Date_Span(); $span1->setFromDateDiff($birth_date1, $post_date1); 
$days_since1 = $span1->format("%D");

the_date is a Wordpress function returning the date of a post.

For this to work, Date package from http://pear.php.net/package/Date/ should be downloaded.

Written by Emre

December 24th, 2009 at 11:28 pm

Posted in Uncategorized

  • Need a line

    require_once 'Date.php'

    and also some changes in php.ini to add the pear package to include_path.
blog comments powered by Disqus