PMP
PMP

Reputation: 231

RoR if statement by datetime

I have a movies database where there is a column called filmstatus, and it has two choices, Upcoming and Released.

To avoid having to change the status every time a movie is released, how would I put the movie release date in an if statement?

Say I add a new movie today and it is released on the 29th of July 2013, how would the statement go?

if the current date is BEFORE 29th July 2013
  puts "Upcoming"
else (so if its AFTER 29th July 2013)
  puts "Released"

Upvotes: 1

Views: 646

Answers (1)

Rahul Chandra
Rahul Chandra

Reputation: 583

  1. Create a release_date:datetime column in the movies table.
  2. Update release_date column to the desired date.

To check the status, you can use the following condition:

if release_date >= Date.today
  status = "Released"
else
  status = "Upcoming"
end

Upvotes: 4

Related Questions