C
Chip
I'm trying to convert a date from an email header like:
Date: Thu, 1 Jan 2004 16:28:41 -0600 (CST)
To the following format:
MM/DD/YYYY
With the following:
if ( $line =~ m/^Date: ..., (.+) (...) /) {
$day = $1;
if ($2 =~ /Jan/){$month = "01";}
if ($2 =~ /Feb/){$month = "02";}
if ($2 =~ /Mar/){$month = "03";}
if ($2 =~ /Apr/){$month = "04";}
if ($2 =~ /May/){$month = "05";}
if ($2 =~ /Jun/){$month = "06";}
if ($2 =~ /Jul/){$month = "07";}
if ($2 =~ /Aug/){$month = "08";}
if ($2 =~ /Sep/){$month = "09";}
if ($2 =~ /Oct/){$month = "10";}
if ($2 =~ /Nov/){$month = "11";}
if ($2 =~ /Dec/){$month = "12";}
$lead_date = "$month/$day/2004";
}
What I need to add is a way to convert 1 to 01, 2 to 02 ect. such as:
if($1 =~ /1/{$day = "01";}
But this would also match 10, 11, 12 and so on,
and if I used "^1?" this would match 11.
What would be the best way to do this?
Thanks
Chip
Date: Thu, 1 Jan 2004 16:28:41 -0600 (CST)
To the following format:
MM/DD/YYYY
With the following:
if ( $line =~ m/^Date: ..., (.+) (...) /) {
$day = $1;
if ($2 =~ /Jan/){$month = "01";}
if ($2 =~ /Feb/){$month = "02";}
if ($2 =~ /Mar/){$month = "03";}
if ($2 =~ /Apr/){$month = "04";}
if ($2 =~ /May/){$month = "05";}
if ($2 =~ /Jun/){$month = "06";}
if ($2 =~ /Jul/){$month = "07";}
if ($2 =~ /Aug/){$month = "08";}
if ($2 =~ /Sep/){$month = "09";}
if ($2 =~ /Oct/){$month = "10";}
if ($2 =~ /Nov/){$month = "11";}
if ($2 =~ /Dec/){$month = "12";}
$lead_date = "$month/$day/2004";
}
What I need to add is a way to convert 1 to 01, 2 to 02 ect. such as:
if($1 =~ /1/{$day = "01";}
But this would also match 10, 11, 12 and so on,
and if I used "^1?" this would match 11.
What would be the best way to do this?
Thanks
Chip