String date comparison

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

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

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:

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.

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

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]?

Philip Hallstrom 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:

Thank you Philip, worked like a charm!