0

Is it possible to save/insert time data with 12hour format using input time?.

instead of having 13:00 as 1:00 PM i want to save it as 1:00 PM. the type of field of the column is var char.

Vincent Dapiton
  • 587
  • 1
  • 9
  • 27
  • 2
    Possible duplicate of [php string in a date format, add 12 hours](http://stackoverflow.com/questions/15228832/php-string-in-a-date-format-add-12-hours) – Sagar Bhut Apr 10 '17 at 06:46
  • You can also get help on this link: http://php.net/manual/en/function.date.php – Vijay Verma Apr 10 '17 at 06:48
  • yes it is, and if you have complete control over the DB column type, I suggest you modify it to date/datetime, then, format your date/hour using [PHP doc date function](http://php.net/manual/en/function.date.php) – OldPadawan Apr 10 '17 at 06:51

2 Answers2

0

You first have to create a date variable and then convert that to the desired format. Assuming your input field name is hour the following should work:

$date=date_create($_GET['hour']); echo date_format($date,"h:i:s a");

For more information about this look at the date page in here: http://php.net/manual/en/function.date.php

0

If you have varchar format in time you can do this...

<?php
if(isset($_POST['submitform'])){
$formattedtime = date('h:i A', strtotime($_POST['time']));
echo $formattedtime;exit;
}
?>

<form action="" method="post" >
<input type="time" name="time" />
<input type="submit" name="submitform">
</form>

Save the formattedtime variable to your database

Rikal
  • 215
  • 2
  • 12