What are all the Rails Date Formats? 3

Posted by Lee Marlow Wed, 20 Aug 2008 22:54:00 GMT

Ever forget what all the Rails defined Date/DateTime/Time#strftime formats are? Or forget what ones you added to the project yourself?

Ala rake routes comes rake date_formats:

Sample output from a Rails 2.1 app:
Date
====
            db:'%Y-%m-%d'   2008-08-20
  long_ordinal:'&proc'      August 20th, 2008
          long:'%B %e, %Y'  August 20, 2008
        rfc822:'%e %b %Y'   20 Aug 2008
        number:'%Y%m%d'     20080820
         short:'%e %b'      20 Aug

DateTime
========
            db:'%Y-%m-%d'   2008-08-20 16:56:21
  long_ordinal:'&proc'      August 20th, 2008 16:56
          long:'%B %e, %Y'  August 20, 2008 16:56
        rfc822:'%e %b %Y'   Wed, 20 Aug 2008 16:56:21 -0600
        number:'%Y%m%d'     20080820165621
         short:'%e %b'      20 Aug 16:56

Time
====
            db:'%Y-%m-%d %H:%M:%S'         2008-08-20 16:56:21
  long_ordinal:'&proc'                     August 20th, 2008 16:56
          long:'%B %d, %Y %H:%M'           August 20, 2008 16:56
        rfc822:'%a, %d %b %Y %H:%M:%S %z'  Wed, 20 Aug 2008 16:56:21 -0600
         short:'%d %b %H:%M'               20 Aug 16:56
        number:'%Y%m%d%H%M%S'              20080820165621
          time:'%H:%M'                     16:56
Comments

Leave a response

  1. Luke Francl Thu, 21 Aug 2008 00:12:31 GMT

    Cool! I just added it to my application. It’s nice to see them all in one place.

  2. Jeremy Pinnix Thu, 21 Aug 2008 01:35:50 GMT

    Excellent job Lee. I just added this output as a cheat sheet:

    $ cheat rails_date_formats

  3. David Andrew Thompson Thu, 21 Aug 2008 18:03:01 GMT

    I added it to my rails gem so that new applications I generate will have the new rake task. To add this functionality just add the code to the routes.rake file under the rails gem folder, so:

    ~/gems/rails-2.1.0/lib/tasks/routes.rake

Comments