note 72412 modified in function.date by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 02:51:17 +0000 |
| Subject: | note 72412 modified in function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141995@lists.php.net to get a copy of this message | ||
I wanted to shift an sql date forward by a set time period.
This is how I achived it... well handy.
<?php
function sql_date_shift($date, $shift)
{
return date("Y-m-d H:i:s" , strtotime($shift, strtotime($date)));
}
// example usage
$date = "2006-12-31 21:00";
$shift "+6 hours"; // could be days, weeks... see function strtotime() for usage
echo sql_date_shift($date, $shift);
// will output: 2007-01-01 03:00:00
?>
Hope it is of use,
Ashley
--was--
I wanted to shift an sql date forward by a set time period.
This is how I achived it... well handy.
<?
function sql_date_shift($date, $shift)
{
return date("Y-m-d H:i:s" , strtotime($shift, strtotime($date)));
}
// example usage
$date = "2006-12-31 21:00";
$shift "+6 hours"; // could be days, weeks... see function strtotime() for usage
echo sql_date_shift($date, $shift);
// will output: 2007-01-01 03:00:00
?>
Hope it is of use,
Ashley
http://php.net/manual/en/function.date.php