Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to extract today's date & time in Rails

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 232
    Comment on it


    If you want to extract only the date, we can use the strftime method of Time/Date class, as

    2.1.5 :055 > DateTime.now.strftime('%d/%m/%Y')
     => "12/30/2015" 
    

    (Here d is used to display date, m displays month and Y display the year in 4-digit format)

    If you want to extract only the time, strftime method of Time/Date class can be used as

    2.1.5 :056 > DateTime.now.strftime('%T')
     => "16:07:50"
    

 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: