jared
1
I am trying to compare dates that I have to the current day’s date so i
can know if something is over due.
this is my code:
<% if assignment[:due_date] < Date.today %>
<%= flash[:notice]=“OVERDUE” %>
the error I keep getting is comparison of String with Date failed.
Any ideas??? thanks in advance
jared
2
Any ideas??? thanks in advance
assignment[:due_date] is a String. To compare dates try this:
if Time.parse(assignment[:due_date]) < Time.now
There may well be a Date.parse method, but I didn’t bother to look ![:slight_smile: :slight_smile:](/images/emoji/twitter/slight_smile.png?v=6)
jared
3
Jared Delux247 wrote:
I am trying to compare dates that I have to the current day’s date so i
can know if something is over due.
this is my code:
<% if assignment[:due_date] < Date.today %>
<%= flash[:notice]=“OVERDUE” %>
the error I keep getting is comparison of String with Date failed.
Any ideas??? thanks in advance
May try replacing “Date.today” with “Date.today.to_s”.
You’ll probably want to make sure the formatting is the same.
Date.today.class
=> Date
Date.today.to_s.class
=> String
Can you give us a preview of what assignment[:due_date]?
jared
4
Philip H. wrote:
Any ideas??? thanks in advance
assignment[:due_date] is a String. To compare dates try this:
if Time.parse(assignment[:due_date]) < Time.now
There may well be a Date.parse method, but I didn’t bother to look ![:slight_smile: :slight_smile:](/images/emoji/twitter/slight_smile.png?v=6)
Thank you Philip, worked like a charm!
jared
5
On 15 Aug 2008, at 22:00, Jared Delux247 wrote:
the error I keep getting is comparison of String with Date failed.
what’s assignment? if it’s something from params then it will just be
a string and you’ll have to convert it to a Date first (Date.parse
etc…)
Fred