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.
--
Guillaume Cottenceau - http://zarb.org/~gc/
> I need a 'Date' object which is converted from a string value
> containing something like '13/04/2005' (english format date).
>
> Help!
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
Glenn Smith <glenn...@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
Farrel
I knew there had to be a clever solution. Nice!
James Edward Gray II
> I need a 'Date' object which is converted from a string value
> containing something like '13/04/2005' (english format date).
>
> Help!
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)
--
Neil Stevens - ne...@hakubi.us
'A republic, if you can keep it.' -- Benjamin Franklin
> ParseDate? It's in Ruby's Std Lib -
> http://www.rubycentral.com/book/lib_standard.html#ParseDate.parsedate
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'.