Create Date from Monthname

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

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

Hi,

Hardy Henneberg <hh@hhenne.dk> 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

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 <hh@hhenne.dk> 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

I guess they are the same as those documented under:

    % ri Time#strftime

HTH,
  Stefan

···

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 ?

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