Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

create Date from Monthname

29 views
Skip to first unread message

Hardy Henneberg

unread,
Oct 31, 2005, 8:23:05 AM10/31/05
to
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

unread,
Oct 31, 2005, 8:34:05 AM10/31/05
to
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

WATANABE Hirofumi

unread,
Oct 31, 2005, 8:50:52 AM10/31/05
to
Hi,

Hardy Henneberg <h...@hhenne.dk> writes:

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

--
eban


Hardy Henneberg

unread,
Oct 31, 2005, 8:59:18 AM10/31/05
to
Thanks,
that's what I was looking for.
BTW - do you have a link to a site defining these formatting symbols ?

regards Hardy

Stefan Lang

unread,
Oct 31, 2005, 9:09:54 AM10/31/05
to
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

unread,
Oct 31, 2005, 9:36:16 AM10/31/05
to
Thank you.
/Hardy
0 new messages