This question already has an answer here:
I have the following DateTime called 'StartTime' field in mysql with '1899-12-30 12:17:52'
I am trying to convert it to a time on the screen for the users with php using
date('h:i:s A',strtotime($row_get_student_times['StartTime']))
but for whatever reason it always returns 4:00 PM no matter what the time. Any clue why this is happening?
</div>
You need to use DateTime:
$datetime = new DateTime($row_get_student_times['StartTime']);
echo $datetime->format('h:i:s A');
It's because you are trying to show a date before the uinx epoch (1970). Try this:
$date = new DateTime($row_get_student_times['StartTime']);
echo $date->format("h:i:s A");
<?php
$dateTimeString = '1899-12-30 12:17:52';
$dateTime = DateTime::createFromFormat('Y-m-d H:i:s', $dateTimeString);
echo $dateTime->format('H:i:s A');