I have two time fields in the table i.e. start_time and end_time
.
When I execute MyModel.save(start_time: '12:34')
, it gets saved with appending a date(Sat, 01 Jan 2000 07:25:00 UTC +00:00)
.
I want to save time only. I am using Rails5
When we execute, a = MyModel.save(start_time: '12:34')
, it saves only time in the database. But when we display the value in the console(a.start_time
), we gets time with date. So we have to retrieve time from it by the following:
a.start_time.strftime("%H:%M")
Data gets correctly saved in the database
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With