note 113011 deleted from function.date-add by googleguy
| From: | googleguy@php.net | Date: | Wed, 23 Oct 2013 00:24:16 +0000 |
| Subject: | note 113011 deleted from function.date-add by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197299@lists.php.net to get a copy of this message | ||
Note Submitter: detain at interserver dot net
----
For those of you looking at this function wanting something that works just like the MySQL
DATE_ADD() function you can use this, it will also work on some older verisons of PHP if you dont
have a 5.3 yet which the date_add() php function does.
<?php
// same thing as below
function mysql_date_add($now = null, $adjustment )
{
preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2})
([0-9]{2}):([0-9]{2}):([0-9]{2})/', $now, $parts);
return date('Y-m-d H:m:s',
(integer)strtotime('+'.trim(str_replace('interval', '',
strtolower($adjustment))),(is_null($now) || trim(strtolower($now)) == 'now()' ? time() :
mktime($parts[4], $parts[5], $parts[6], $parts[2], $parts[3], $parts[1]))));
}
?>