I need a 'Date' object which is converted from a string value
containing something like '13/04/2005' (english format date).
Help!
···
--
All the best
Glenn
Aylesbury, UK
I need a 'Date' object which is converted from a string value
containing something like '13/04/2005' (english format date).
Help!
--
All the best
Glenn
Aylesbury, UK
Pleac?
http://pleac.sourceforge.net/pleac_ruby/datesandtimes.html#AEN153
But there sure miss some more/better information there.
On 4/13/05, Glenn Smith <glenn.ruby@gmail.com> wrote:
I need a 'Date' object which is converted from a string value
containing something like '13/04/2005' (english format date).
--
Guillaume Cottenceau - http://zarb.org/~gc/
This isn't a particularly brilliant answer, so hopefully someone will do better:
ruby -r date -e 'puts Date.parse("13/04/2005".split("/").values_at(1, 0, 2).join("/"))'
Hope that helps.
James Edward Gray II
On Apr 13, 2005, at 8:36 AM, Glenn Smith wrote:
I need a 'Date' object which is converted from a string value
containing something like '13/04/2005' (english format date).Help!
Hi,
Glenn Smith <glenn.ruby@gmail.com> writes:
I need a 'Date' object which is converted from a string value
containing something like '13/04/2005' (english format date).
% ruby -rdate -e 'puts Date.strptime("13/04/2005", "%d/%m/%Y")'
2005-04-13
--
eban
ParseDate? It's in Ruby's Std Lib -
http://www.rubycentral.com/book/lib_standard.html#ParseDate.parsedate
Farrel
If you're certain it's that date format:
require 'date'
parts = '13/04/2005'.split('/').reverse
parts = parts.collect do |i|
i = i.to_i
end
date = Date.new(*parts)
On Wed, 13 Apr 2005 23:36:10 +0900, Glenn Smith wrote:
I need a 'Date' object which is converted from a string value
containing something like '13/04/2005' (english format date).Help!
--
Neil Stevens - neil@hakubi.us
'A republic, if you can keep it.' -- Benjamin Franklin
I knew there had to be a clever solution. Nice!
James Edward Gray II
On Apr 13, 2005, at 8:49 AM, WATANABE Hirofumi wrote:
Hi,
Glenn Smith <glenn.ruby@gmail.com> writes:
I need a 'Date' object which is converted from a string value
containing something like '13/04/2005' (english format date).% ruby -rdate -e 'puts Date.strptime("13/04/2005", "%d/%m/%Y")'
2005-04-13
Nope, that assumes month/day/year when it sees that style. It can only
support one or the other thanks to cases like '1/2/2005'.
On Wed, 13 Apr 2005 23:50:12 +0900, Farrel Lifson wrote:
ParseDate? It's in Ruby's Std Lib -
http://www.rubycentral.com/book/lib_standard.html#ParseDate.parsedate
--
Neil Stevens - neil@hakubi.us
'A republic, if you can keep it.' -- Benjamin Franklin
Thanks guys - I'm getting jumpy about my demo tomorrow!
G
On 4/13/05, James Edward Gray II <james@grayproductions.net> wrote:
On Apr 13, 2005, at 8:49 AM, WATANABE Hirofumi wrote:
> Hi,
>
> Glenn Smith <glenn.ruby@gmail.com> writes:
>
>> I need a 'Date' object which is converted from a string value
>> containing something like '13/04/2005' (english format date).
>
> % ruby -rdate -e 'puts Date.strptime("13/04/2005", "%d/%m/%Y")'
> 2005-04-13I knew there had to be a clever solution. Nice!
James Edward Gray II
--
All the best
Glenn
Aylesbury, UK
It was exactly this problem I was having Neil (ie. using ParseDate on
'13/04'2005' gave me an error - I think it didn't like there being 13
months!)
On 4/13/05, Neil Stevens <neil@hakubi.us> wrote:
On Wed, 13 Apr 2005 23:50:12 +0900, Farrel Lifson wrote:
> ParseDate? It's in Ruby's Std Lib -
> http://www.rubycentral.com/book/lib_standard.html#ParseDate.parsedateNope, that assumes month/day/year when it sees that style. It can only
support one or the other thanks to cases like '1/2/2005'.--
Neil Stevens - neil@hakubi.us'A republic, if you can keep it.' -- Benjamin Franklin
--
All the best
Glenn
Aylesbury, UK