Store the day of the week and time?

后端 未结 4 1935
一向
一向 2020-12-09 21:26

I have a two-part question about storing days of the week and time in a database. I\'m using Rails 4.0, Ruby 2.0.0, and Postgres.

I have certain events, and those ev

4条回答
  •  爱一瞬间的悲伤
    2020-12-09 22:22

    Why not just store the datestamp then use the built in functionality for Date to get the day of the week?

    2.0.0p247 :139 > Date.today
     => Sun, 10 Nov 2013 
    2.0.0p247 :140 > Date.today.strftime("%A")
     => "Sunday" 
    

    strftime sounds like it can do everything for you. Here are the specific docs for it.

    Specifically for what you're talking about, it sounds like you'd need an Event table that has_many :schedules, where a Schedule would have a start_date timestamp...

提交回复
热议问题