CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: split string into dates: Edit Log



alferic
Novice

Apr 7, 2014, 12:59 AM


Views: 23992
split string into dates

hello Gurus,

I need your valuable ideas on how to resolve my regex isssue.

I have this date strings from a excel file which may contain any of the following format:

3122014_50437_AM ##read as Mar 12, 2014 5:04:37 AM
112014_112532_PM ##read as Jan 1,2014 11:25:32 PM
12152013_63524_PM ##read as Dec 15, 2014 6:35:24 PM

I wanted the perl script that when it sees the string to split this string into pieces so that I can convert them to timegm(). I tried the regex below but it is not dynamic to every combination of date strings.

here's a portion of my script.

#the $mydate variable may contain any of the above date string combinations.

my ($mmddyyyy, $hhmmss, $ampm) = split /\_/, $mydate;

my ($mm, $dd, $yy) = $mmddyyyy =~ /\b(\d{2})(\d{2})(\d{4})\b/;

my ($hr, $min, $ss) = $hhmmss =~ /\b(\d{2})(\d{2})(\d{2})\b/;

print ("$mm\/$dd\/$yy $hr\:$min\:$ss\n";

$datetime = timegm($ss, $min, $hr, $dd, $mm-1, $yy);

print "$datetime\n";


(This post was edited by alferic on Apr 7, 2014, 1:04 AM)


Edit Log:
Post edited by alferic (Novice) on Apr 7, 2014, 1:04 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives