Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9106001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:14:05+00:00 2026-06-17T02:14:05+00:00

Now I’m trying to make helper method like this. How can I compare the

  • 0

Now I’m trying to make helper method like this.
How can I compare the datetime of argument with Today’s date?

def todate_datetime(date_time)
    date_time = Date.today ? "<font color='red'>#{date_time}</font>" : date_time
end

UPDATE:

view

<%= today_datetime(community_topic.updated_at) %>

helpers

def today_datetime(date_time)
  date_time == Date.today ? "<font color='red'>#{date_time.to_s(:ct)}</font>" : date_time.to_s(:ct)
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:14:06+00:00Added an answer on June 17, 2026 at 2:14 am

    Starting from ruby 1.9.2 you can directly compare a DateTime object with a Date object in ruby, e.g. try in irb:

    require 'date'
    today = DateTime.new(2013,1,4)
     => #<DateTime: 2013-01-04T00:00:00+00:00 ((2456297j,0s,0n),+0s,2299161j)> 
    today == Date.today
    => true
    

    However, Rails has its own DateTime object (APIdock Rails DateTime). One option is to convert the Rails Object to a date via the to_date method

    So then the helper method could look like this:

    def todate_datetime(date_time)
      date_time.to_date == Date.today ? "<font color='red'>#{date_time}</font>" : date_time
    end
    

    EDIT: it might be more accurate to compare the date_time argument to DateTime.current.to_date since that takes the config.time_zone into account if set:

    def todate_datetime(date_time)
      date_time.to_date == DateTime.current.to_date ? "<font color='red'>#{date_time}</font>" : date_time
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

now in web2py every field in the db look like this in the form
Now I have routing set up like this. resources :communities do resources :community_topics end
Now for some reason i can't get this code to work When i move
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Now I'm not sure if this is something I'm doing wrong, or something thats
Now I'm trying to display the result of consuming a webservice from one page
Now I have a long query and I'd like to alternate with such a
I have a jquery bug and I've been looking for hours now, I can't
Now I am trying to update my ruby version from 1.8(system default) to 1.9.3.
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.