DateTime.strptime(date_string, "%d/%m/%Y %H:%M:%S") , I would get the
argument error, when *date_string* will not be having the format
"%d/%m/%Y %H:%M:%S".
What is the correct way to handle this using `Date::strptime`. I
wouldn't use `Date::parse`.
DateTime.strptime(date_string, "%d/%m/%Y %H:%M:%S") , I would get the
argument error, when *date_string* will not be having the format
"%d/%m/%Y %H:%M:%S".
What is the correct way to handle this using `Date::strptime`. I
wouldn't use `Date::parse`.
begin
DateTime.strptime(date_string, "%d/%m/%Y %H:%M:%S")
rescue ArgumentError
begin
DateTime.strptime(date_string, "%d/%m/%Y %H:%M")
rescue ArgumentError
begin
...
It feels clunky but it works, and it can be made more elegant by turning it into a loop.
You could also use a case with regexes.
- A
···
On Mar 18, 2014, at 9:30 AM, Arup Rakshit <lists@ruby-forum.com> wrote:
DateTime.strptime(date_string, "%d/%m/%Y %H:%M:%S") , I would get the
argument error, when *date_string* will not be having the format
"%d/%m/%Y %H:%M:%S".
What is the correct way to handle this using `Date::strptime`. I
wouldn't use `Date::parse`.