Jump to content

Working with "time" field in PHP


tekrscom

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.