note 85987 added to function.mktime
| From: | zola at zolaweb dot com | Date: | Sat, 27 Sep 2008 08:27:44 +0000 |
| Subject: | note 85987 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144830@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 151.205.41.40
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- https://master.php.net/note/edit/85987
Del: integrated -- https://master.php.net/note/delete/85987/integrated
Del: useless -- https://master.php.net/note/delete/85987/useless
Del: bad code -- https://master.php.net/note/delete/85987/bad+code
Del: spam -- https://master.php.net/note/delete/85987/spam
Del: non-english -- https://master.php.net/note/delete/85987/non-english
Del: in docs -- https://master.php.net/note/delete/85987/in+docs
Del: other reasons-- https://master.php.net/note/delete/85987
Reject -- https://master.php.net/note/reject/85987
Search -- https://master.php.net/manage/user-notes.php