> -----Original Message----- > From: Chris Boget [mailto:chris.boget@xxxxxxxx] > Sent: Monday, June 18, 2007 10:55 AM > To: Brad Bonkoski; Richard Kurth > Cc: php-general@xxxxxxxxxxxxx > Subject: Re: subtracting time from date and time > > > 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 )); This works great tell you get to 8 hours ago it shows the correct time but it does not change the date to the day before. 8 hours ago should be 06/16/2007 11:35:00 but what it shows is 06/17/2007 11:35:00 $str = "20070617T193500"; $timestamp = strtotime( $str ); $oneMinute = 60; // seconds $oneHour = $oneMinute * 60; $oneDay = $oneHour * 24; echo 'time: ' . date( 'm/d/Y h:i:s', $timestamp ); echo"<br>"; echo '5 minutes ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneMinute *5 )); echo"<br>"; echo '15 minutes ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneMinute *15 )); echo"<br>"; echo '30 minutes ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneMinute *30 )); echo"<br>"; echo '1 hours ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneHour * 1 )); echo"<br>"; echo '2 hours ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneHour * 2 )); echo"<br>"; echo '5 hours ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneHour * 5 )); echo"<br>"; echo '7 hours ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneHour * 7 )); echo"<br>"; echo '8 hours ago: ' . date( 'm/d/Y h:i:s', $timestamp - ( $oneHour * 8)); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php