简体   繁体   中英

Saving bootstrap time picker value in PHP and MYsql

I am using bootstrap timepicker to select the shift start time and shift end time.I am posting the start time and end time values to a another php script to store it in Database. I used strtotime function to convert the timepicker values and then store it in database but no luck. Both the times in the database value are stored as same value even after converting.

$converted_starttime = strtotime($_POST['starttime']);
$converted_endtime = strtotime($_POST['endtime']);

I also want to do the comparisons using this shift start time and shift end time. Is there any better way to store the timepicker values into the database so that it can be easily used for comparisons. Any help is appreciated.

solution :

change the database type in integer you can not save int in time type field

SEE THIS

strtotime converts the value to a linux timestamp which is a number. If you must save as a datetime in the database then you need to pass the correct datetime format.

Something like:

$datetime=date('Ymd H:i:s',strtotime($_POST['starttime']);

make sure to use correct separator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM