Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > create Date from Monthname

Reply
Thread Tools

create Date from Monthname

 
 
Hardy Henneberg
Guest
Posts: n/a
 
      10-31-2005
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


 
Reply With Quote
 
 
 
 
David Teare
Guest
Posts: n/a
 
      10-31-2005
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
>
>




 
Reply With Quote
 
 
 
 
WATANABE Hirofumi
Guest
Posts: n/a
 
      10-31-2005
Hi,

Hardy Henneberg <(E-Mail Removed)> 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


 
Reply With Quote
 
Hardy Henneberg
Guest
Posts: n/a
 
      10-31-2005
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 <(E-Mail Removed)> 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
>
>
>



 
Reply With Quote
 
Stefan Lang
Guest
Posts: n/a
 
      10-31-2005
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


 
Reply With Quote
 
Hardy Henneberg
Guest
Posts: n/a
 
      10-31-2005
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
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want date as MonthName, day, year anony ASP .Net 1 08-02-2004 09:09 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C Programming 3 11-08-2003 09:07 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments