Date Time insert error

Clash Royale CLAN TAG#URR8PPP
Date Time insert error
I am using bootstrap date time picker and when I try to insert selected date time it showing me an error
"SQLSTATE[22007]: Invalid date time format: 1292 Incorrect date time value: '21 December 2012 - 03:25 PM' for column 'startDate' at row 1 "
then I used in my controller
$iVisitors->startDate = date("Y-d-m H:i:s", strtotime(request('startDate')));
but now it stores a default time 1970-01-01 00:00:00 not my selected time. How can I store my selected date time?
1 Answer
1
The format of the datetime being passed to php's strtotime() is wrong. You could simply replace the - that appears before the time with an empty string using php's str_replace(), i.e.
-
$iVisitors->startDate = date("Y-d-m H:i:s", strtotime(str_replace('- ', '', request('startDate'))));
so that 21 December 2012 - 03:25 PM now becomes 21 December 2012 03:25 PM.
$iVisitors->startDate = date("Y-d-m H:i:s", strtotime(str_replace('- ', '', request('startDate'))));
21 December 2012 - 03:25 PM
21 December 2012 03:25 PM
You are getting 1970-01-01 00:00:00 because strtotime is returning false and so php's date is also returning its start date.
1970-01-01 00:00:00
You can checkout the strtotime php manual page for more information. You could also easily specify the format being returned from the datepicker script by setting an acceptable format.
Kindly check your request('startDate') value
– Xixis
Aug 12 at 12:40
Thank you very much
– Md. Abu Zaman
Aug 12 at 13:00
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
now showing another exception: "ErrorException (E_WARNING) Creating default object from empty value"
– Md. Abu Zaman
Aug 12 at 11:36