Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to ordinalize current date in rails

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 294
    Comment on it


    Rails provide us many features which are native to Rails and not ruby.

    We can ordinalize a date in rails with a method provided by active_support known as ordinalize.

    If we want to ordinalize today's date we can write :-

    2.1.5 :01 > t = Time.now
     => 2015-12-30 15:20:58 +0530
    2.1.5 :03 > t.strftime("#{tday.ordinalize} %B %Y")
     => "30th December 2015"
    

    (Here B is used to display month's Name and Y display the year in 4-digit format)

    Thus we can see that it appended th after the date i.e 30th, this is the ordinalized form.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: