Insert Date Data Using Laravel’s Eloquent ORM

I have a difficulty in inserting date data with Laravel’s Eloquent ORM. The issue is I didn’t use the right format for the date input. I used mm/dd/yyyy format while the SQL statement requires me to use yyyy/mm/dd format. I need to convert the date form to the approriate format. How I did it? Lets see. 😀

I retrieve the controller with Input::get() and assign it’s value to an Eloquent object. For example:

$event->start_date = date("Y-m-d", strtotime(Input::get('start_date')));

I use strtotime function to convert the date to the number of seconds since January 1 1970 00:00:00 UTC. After that I create a date object with “Y-m-d” format and assign it to start_date attribute.

That’s all! 😀

Nanda Firdaus

Ex-engineer who is switching to product management role in Traveloka. Passionate about new technology and have interest in product development, business, and investment. Ex-Microsoft Student Partner. Master of Information System Management at Carnegie Mellon University. Bachelor of Information System, Faculty of Computer Science, Universitas Indonesia.

You may also like...

Leave a Reply

Your email address will not be published.