note 47749 added to function.mktime
| From: | cp at u-help dot org | Date: | Sun, 28 Nov 2004 01:53:00 +0000 |
| Subject: | note 47749 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81110@lists.php.net to get a copy of this message | ||
I once had to deal with dates coming in as a sting from a mysql database (surprise, surprise ;-))
without having any option to select anything differen (i.e. using mysql's UNIX_TIMESTAMP)
This caused me a lot of problems and I couldn't seem to find anything anywhere that would just
take the entire lot as an input to convert it to unix-timestamp.
Maybe someone else finds the below function useful to convert these date/time strings into
unix-timestamps
<?php
function dttm2unixtime($dttm2timestamp_in){
// returns unixtime stamp for a given date time string that comes from DB
$date_time = explode(" ", $dttm2timestamp_in);
$date = explode("-",$date_time[0]);
$time = explode(":",$date_time[1]);
unset($date_time);
list($year, $month, $day)=$date;
list($hour,$minute,$second)=$time;
return mktime(intval($hour), intval($minute), intval($second), intval($month), intval($day),
intval($year));
}
?>
A mysql date-time value like "2004-11-28 01:34:20" would be converted to this: 1101605660
As a verification, date("Y-m-d H:i:s", 1101605660) would return the same as the value
passed in, i.e. 2004-11-28 01:34:20
Using the function above, you don't have to include any fancy parsing into the retrieval of the
results...
hope it helps ;)
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47749
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47749&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47749&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47749&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47749&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47749&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47749&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47749&report=yes
Search -- http://master.php.net/manage/user-notes.php