tekrscom Posted June 20, 2010 Share Posted June 20, 2010 Hi, I have been searching and searching, reading all of the different "time" related manuals on php.net and other various places, but I cannot find any information that deals with PHP manipulating a MySQL "time" field only... they are all date/time field manipulation... Inserting a time into MySQL was easy, like so... if ($_POST['TimeInAMPM'] == 'PM') { if ($_POST['TimeInHour'] != 12) { $TimeInHour = $_POST['TimeInHour'] + 12; } else { $TimeInHour = 12; } } elseif ($_POST['TimeInAMPM'] == 'AM') { $TimeInHour = $_POST['TimeInHour']; } if ($_POST['TimeOutAMPM'] == 'PM') { if ($_POST['TimeOutHour'] != 12) { $TimeOutHour = $_POST['TimeOutHour'] + 12; } else { $TimeOutHour = 12; } } elseif ($_POST['TimeOutAMPM'] == 'AM') { $TimeOutHour = $_POST['TimeOutHour']; } $TimeStarted = $TimeInHour.':'.$_POST['TimeInMinutes'].':00'; $TimeEnded = $TimeOutHour.':'.$_POST['TimeOutMinutes'].':00'; But trying to work with the time after pulling it out of the database is another story... For showing the time purposes, I'd like to look like this, 8:45 AM or 3:15 PM... So I tried a few things, such as this... $ThisTimeStarted = date("g:i A", $row['TimeStarted']); $ThisTimeEnded = date("g:i A", $row['TimeEnded']); But they didn't work... For editing purposes, I would like to be able to split the hours and minutes, so that I can match them in a select drop down box... I guess ultimately if I could figure out how to split the hour and minutes from a MySQL field with PHP, I could figure out the rest... Link to comment https://forums.phpfreaks.com/topic/205333-working-with-time-field-in-php/ Share on other sites More sharing options...
Mchl Posted June 20, 2010 Share Posted June 20, 2010 $ThisTimeEnded = date("g:i A", strtotime($row['TimeEnded'])); Link to comment https://forums.phpfreaks.com/topic/205333-working-with-time-field-in-php/#findComment-1074669 Share on other sites More sharing options...
tekrscom Posted June 20, 2010 Author Share Posted June 20, 2010 I thought I had tried that, but apparently I hadn't... thank you... worked like a charm... $ThisTimeEnded = date("g:i A", strtotime($row['TimeEnded'])); Link to comment https://forums.phpfreaks.com/topic/205333-working-with-time-field-in-php/#findComment-1074756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.