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:

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

Graduate Student in Information System Management at Carnegie Mellon University. Previously worked as Marketing Technology Analyst and Data Analyst in Passionate about new technology and have interest in data, business and investment. Ex-Microsoft Student Partner. Graduated from Information System, Faculty of Computer Science, Universitas Indonesia.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *