-2

I need to store time which is in the form of HH: MM AM/PM which is entered from angular js front end.

HTML

<input type="time" ng-model="booktime">

Controller

$http.post("url", { 
    'booktime':booktime,
    .then(function(response) {
    },function(error) {
        alert("");
        console.error(error);
    });
}

Mysql

$sql = "INSERT INTO table(booktime)
VALUES (TIME_FORMAT( '11:00:00', '%h:%i:%s %p' ))";
Manoj Sharma
  • 1,467
  • 2
  • 13
  • 20

1 Answers1

-1

You SHOULD NOT insert datetime in any other format than YYYY-MM-DD HH:MM:SS.

If you want to show to user formatted time, then do it whilst/after retrieving it from a database. For example in SELECT query:

SELECT TIME_FORMAT(booktime, '%h:%i:%s %p') AS booktime FROM table

or in your view.

Albert221
  • 5,223
  • 5
  • 25
  • 41