From: Clement Ow Date: 2008-04-23T17:38:08+09:00 Subject: Re: Extract date from filenames using regex Jes��s Gabriel y Gal��n wrote: > On Wed, Apr 23, 2008 at 9:50 AM, Jes?briel y > Gal���lt;jgabrielygalan@gmail.com> wrote: >> On Wed, Apr 23, 2008 at 9:14 AM, Clement Ow >> >> wrote: > >> 1.- Change DateTime.parse to DateTime.strptime passing a format >> that describes where in the string you have the two digits of the day, the month >> and the four digits of the date. I haven't been able to gather a quick example, >> cause I don't find a reference for the format string (any help here >> appreciated). >> The doc refers me to the date/format.rb for details and I don't see >> anything clear >> there. > > After a couple of trial/error tests this seems to work: > > DateTime.strptime "16042008", "%d%M%Y" > > So any of the two solutions will work for you. > > Jesus. Hi Jesus, First of all thanks for your help! However, Despite using d= DateTime.civil (match[1].to_i, match[2].to_i, match[3].to_i) file_date=d.to_s OR file_date = DateTime.strptime (match[1], "%d%M%Y") it still gives me invalid date as the error msg. But when i run it in the fxri it seems to work fine.. This only seems to happen when the date format is ddmmyyyy, but for yyyymmdd it has no problems though.. Any ideas anyone? I have cracked my head but to no avail. -- Posted via http://www.ruby-forum.com/.