beginner beginner - 1 year ago 96
Javascript Question

Convert JavaScript type time to MySQL time

In my HTML I have an input type

, and I want to insert this value in a column type "time" in MySQL using PHP. How can I do this?

<label class="item item-input">
<span class="input-label">Heure de d├ępart </span>
<input type="time" placeholder="hh:mm" ng-model="heureDepart"><!-- datetime -->

The time looks like
Thu Jan 01 1970 10:00:00 GMT+0000 (Maroc)
in HTML. I just want to save the value
in MySQL because I have a column type "time" in my database.

Answer Source

You could try this, basically using the DataTime class in PHP will allow you to convert pretty much any datetime format into any other like so

$str = 'Thu Jan 01 1970 10:11:12 GMT+0000 (Maroc)';
try {
    $date = new DateTime($str);
} catch (Exception $e) {
    echo $e->getMessage();

echo $date->format('H:i:s');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download