I want to get Only Hours From date by using PHP & Cakephp function.
$date = "2011-07-26 20:05:00"; $hours = ?
Try this: $hourMin = date('H:i'); This will be 24-hour time with an hour that is always two digits. For all options, see the PHP docs for date().
You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.
PHP time() Functionecho(date("Y-m-d",$t));
A timestamp in PHP is a numeric value in seconds between the current time and value as at 1st January, 1970 00:00:00 Greenwich Mean Time (GMT). The value returned by the time function depends on the default time zone. The default time zone is set in the php.
Use the Datetime
class (PHP 5.3 or higher).
$dt = DateTime::createFromFormat("Y-m-d H:i:s", "2011-07-26 20:05:00"); $hours = $dt->format('H'); // '20'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With