Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save only time in rails

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

like image 939
Chakreshwar Sharma Avatar asked Jan 02 '18 07:01

Chakreshwar Sharma


1 Answers

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

like image 192
Chakreshwar Sharma Avatar answered Oct 28 '22 22:10

Chakreshwar Sharma