Re: subtracting time from date and time

From: Date: Mon, 18 Jun 2007 17:54:41 +0000
Subject: Re: subtracting time from date and time
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-257327@lists.php.net to get a copy of this message
Something like this will get it into a time stamp...and then you can do your calculations with ease, and reformat... <?php
       $str = "20070617T193500";
       list($date, $time) = explode("T",$str);
?>
Even easier: $timestamp = strtotime( $str ); http://us2.php.net/manual/en/function.strtotime.php $oneMinute = 60; // seconds
$oneHour    = $oneMinute * 60;
$oneDay     = $oneHour * 24;
echo '5 minutes ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneMinute * 5 )); echo '5 hours ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneHour * 5 )); echo '5 days ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneDay * 5 )); etc., etc., etc. thnx, Chris

« previous php.general (#257327) next »