How would I get the hours from a DATETIME format variable.
Example: 2009-08-17 13:00:00
And I just need to get '13'
How would I get the hours from a DATETIME format variable.
Example: 2009-08-17 13:00:00
And I just need to get '13'
You can use the HOUR()
function:
mysql> SELECT HOUR('2009-08-17 13:00:00');
+-----------------------------+
| hour('2009-08-17 13:00:00') |
+-----------------------------+
| 13 |
+-----------------------------+
in php,
list($date, $time) = explode(' ', '2009-08-17 13:00:00');
list($hour, $min, $sec) = explode(':', $time);
$hour should contain 13.