note 85987 deleted from function.mktime by danbrown
| From: | danbrown@php.net | Date: | Tue, 02 Nov 2010 17:20:15 +0000 |
| Subject: | note 85987 deleted from function.mktime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173691@lists.php.net to get a copy of this message | ||
Note Submitter: zola at zolaweb dot com
----
You can't use something along the lines of
$mydate = '2008-27-09 3:52:06';
$x = mktime(date("Y", $mydate), date("m", $mydate), date("d",
$mydate), date("H", $mydate), date("i", $mydate), date("s",
$mydate));
because mktime will puke on the leading zeroes, you'll get "Notice: A non well formed
numeric value encountered in ...."
There's no setting to get seconds without leading zeros, at least not yet, so you have to
prepare your date string first.
You can explode your date as some examples have shown, and then either multiply each result by 1 to
remove the leading zero, or trim them off, but even simpler is to convert to the unix epoch:
$convert_date = date('U', strtotime($mydate));
You can add or subtract time in the ordinary way
$convert_date = date('U', strtotime("+1 day", $mydate));
and then convert it back to your preferred dateformat without invoking mktime at all.
$mynewdate = date('Y-m-d H:i:s', $convert_date);
Hopefully this will be useful if you are trying to calculate from an already formatted date, such as
one grabbed from a database or mail.