Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get time from datetime

I have datetime 30-12-1899 9:25:52 AM here needed only time that is 9:25:52 AM .this time i wanted to insert in mysql database and this field has data type time.

my code is :

<?php
$date = "30-12-1899 9:25:52 AM";
$date = strtotime($date);
echo date('H:i:s', $date);
?> 

when execute it returns:

01:00:00

i am not getting where is the problem.Can any one help me on this.

thank you.

like image 470
snehal Avatar asked Nov 25 '13 10:11

snehal


1 Answers

Do the OOP way

<?php
$date1="30-12-1899 9:25:52 AM";
$format = 'd-m-Y H:i:s A';
$date = DateTime::createFromFormat($format, $date1);
echo $date->format('H:i:s A') . "\n";
like image 119
Shankar Narayana Damodaran Avatar answered Sep 29 '22 12:09

Shankar Narayana Damodaran