How to convert UNIX timestamp to MySQL
I have columns in a table defined with a date 'YYYY-MM-DD' (data type: date) and time 'HH-MM-SS "(data: time) must.
Now I would like the entries in / out lines and such are within a defined date. For each line, the overall total of the time are calculated.
I get a multi figure I assume that it is the Unixtimestamp act. How do I reformat now, again a time HH-MM-SS arises. For example, 68:50:00.
Re: How to convert UNIX timestamp to MySQL
Timestamp format in Mysql Datetime in general when you change
select FROM _UNIXTIME (int timestatmp)
If an opposition?
select TO_UNIXTIME (datetime)
select UNIX _TIMESTAMP (datetime)
Re: How to convert UNIX timestamp to MySQL
Why you walking the timestamp is not equal when you save the DB in order? Obviously has the disadvantage that because you no longer so closely with the time stamp can sort. you can easily do it in PHP.
Quote:
<?php
/**
*
* @convert UNIX TIMESTAMP to MySQL TIMESTAMP
*
* @param int $timestamp
*
* @return string
*
*/
function unixToMySQL($timestamp)
{
return date('Y-m-d H:i:s', $timestamp);
}
/*** example usage ***/
$time = time();
echo unixToMySQL($time);
?>