Kody Kody - 1 year ago 120
jQuery Question

Convert date format to mysql timestamp

Very stumped about this,

I have a text input field that allows the user to insert a date and time with jquery's date picker and a timepicker addon. When the user closes the calendar to insert the date, It enters this into the text field:

10/13/2013 22:16
. How do I convert this with php to a mysql timestamp function suitable for database storage?
2013-10-13 22:16:00

Thank You!

Answer Source

This is the only logical way I've figured out how to accomplish this with PHP.

$Data  = $_POST['date'];
$Data  = explode("/", $Data);
$Month = $Data[0];
$Day   = $Data[1];
$YearAndTime = explode(" ", $exp[2]);
$Year = $YearAndTime[0];
$T = explode(":", $YearAndTime[1]);
$Hour = $T[0];
$Minute = $T[1];
$timestamp = "{$Year}-{$Month}-{$Day} {$Hour}:{$Minute}:00";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download