create Date from Monthname

Discussion in 'Ruby' started by Hardy Henneberg, Oct 31, 2005.

  1. Hi,
    I have a string of format: '28/Sep/2005'.
    I am looking for the easiest way to create a Date from that string.
    I don't want to make my own conversion of monthname to monthnumber if
    not needed.

    regards
    Hardy
     
    Hardy Henneberg, Oct 31, 2005
    #1
    1. Advertising

  2. Hardy Henneberg

    David Teare Guest

    DateTime.parse works for me when using the format "2005-Oct-12". I
    tried with yours, and it doesn't like the slashes, but it was smart
    enough to figure out the order of the date:

    require 'date'
    d = DateTime.parse("28-Sep-2005")
    d.to_s => "2005-09-28T00:00:00Z"

    So, I would just do a gsub before calling parse. i.e. d =
    DateTime.parse("28/Sep/2005".gsub!("/", "-"))

    HTH

    On 31-Oct-05, at 8:23 AM, Hardy Henneberg wrote:

    > Hi,
    > I have a string of format: '28/Sep/2005'.
    > I am looking for the easiest way to create a Date from that string.
    > I don't want to make my own conversion of monthname to monthnumber
    > if not needed.
    >
    > regards
    > Hardy
    >
    >
     
    David Teare, Oct 31, 2005
    #2
    1. Advertising

  3. Hi,

    Hardy Henneberg <> writes:

    > Hi,
    > I have a string of format: '28/Sep/2005'.
    > I am looking for the easiest way to create a Date from that string.
    > I don't want to make my own conversion of monthname to monthnumber if
    > not needed.


    % ruby -rdate -e 'puts Date.strptime("28/Sep/2005", "%d/%b/%Y")'
    2005-09-28

    --
    eban
     
    WATANABE Hirofumi, Oct 31, 2005
    #3
  4. Thanks,
    that's what I was looking for.
    BTW - do you have a link to a site defining these formatting symbols ?

    regards Hardy

    WATANABE Hirofumi wrote:

    >Hi,
    >
    >Hardy Henneberg <> writes:
    >
    >
    >
    >>Hi,
    >>I have a string of format: '28/Sep/2005'.
    >>I am looking for the easiest way to create a Date from that string.
    >>I don't want to make my own conversion of monthname to monthnumber if
    >>not needed.
    >>
    >>

    >
    >% ruby -rdate -e 'puts Date.strptime("28/Sep/2005", "%d/%b/%Y")'
    >2005-09-28
    >
    >
    >
     
    Hardy Henneberg, Oct 31, 2005
    #4
  5. Hardy Henneberg

    Stefan Lang Guest

    On Monday 31 October 2005 14:59, Hardy Henneberg wrote:
    > Thanks,
    > that's what I was looking for.
    > BTW - do you have a link to a site defining these formatting
    > symbols ?


    I guess they are the same as those documented under:

    % ri Time#strftime

    HTH,
    Stefan
     
    Stefan Lang, Oct 31, 2005
    #5
  6. Thank you.
    /Hardy

    Stefan Lang wrote:

    >On Monday 31 October 2005 14:59, Hardy Henneberg wrote:
    >
    >
    >>Thanks,
    >>that's what I was looking for.
    >>BTW - do you have a link to a site defining these formatting
    >>symbols ?
    >>
    >>

    >
    >I guess they are the same as those documented under:
    >
    > % ri Time#strftime
    >
    >HTH,
    > Stefan
    >
    >
    >
    >
    >
     
    Hardy Henneberg, Oct 31, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    608
    Matthew Speed
    Nov 8, 2003
  2. anony

    Want date as MonthName, day, year

    anony, Aug 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    361
    Eliyahu Goldin
    Aug 2, 2004
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,278
    Michael Borgwardt
    May 30, 2004
  4. Matt
    Replies:
    2
    Views:
    519
    Pete Becker
    Nov 8, 2003
  5. Matt
    Replies:
    3
    Views:
    724
    Richard Heathfield
    Nov 8, 2003
Loading...

Share This Page