If a date with no time on it, why not just use a date field? Read the mysql docs on date and datetime fields.
Nov 5, 2016
9
Level 1
Convert Time To TimeStamp
Hi I have date-picker ( js plugin) that sends the date as this format : 11/05/2016 I want to save that to time-stamp column in MySQL database ... how do I convert this date format to time-stamp in back-end side ?
Level 54
@Mohsen Specify the format.. obviously carbon won't be able to determine if the second or third part of that date is month, and which is day.. instead of parse in this case you should use createFromFormat()
$timestamp = \Carbon\Carbon::createFromFormat('Y/m/d', '2016/05/05')->timestamp;
EDIT: You changed your date format in your post while I was replying.. but even so.. use createFromFormat to ensure the proper order of month, day, year is used by carbon.
5 likes
Please or to participate in this conversation.