Checking date of birth is greater than today

Posted on 2007-11-20
Last Modified: 2008-02-01

I need to dob is greater than today and this is what I did, but I get this error:

undefined method `/' for Tue Nov 20 14:21:26 -0500 2007:Time

class AttendingIp < ActiveRecord::Base
def validate_on_create(today = Date::today)
    if dob >
      errors.add("dob", "Date of birth must be less than " + + ".")

Question by:dkim18
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 60

Expert Comment

by:Geert Bormans
ID: 20326311 generates a time string in this format "Wed Nov 21 09:50:01 +0100 2007"
you can't use that in calculations,
so this will not work

if you need to create a Date object from today,
all you need is
today =
LVL 19

Expert Comment

ID: 20375605

Do you need further assistance with comparing dates?

Phil / peh803

Accepted Solution

rbarazi earned 350 total points
ID: 20423438
Use this snippet if your dob column is date (which is how it's supposed to be), otherwise use instead
validate_on_create :validate_dob
  def validate_dob
    if self.dob >
      errors.add("dob", "Date of birth must be less than #{}")

Open in new window


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below:…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question