first populate an array with the month abbreviations:
$month[1] = 'JAN';
$month[2] = 'FEB';
$month[3] = 'MAR';
#....and so on....
then do the substitution:
$date =~ m/ (\d+)-(\d+)-(\d{2}(\d{2})/;
$day = $1;
$month_num = $2;
$year = $3;
if (length($day)<2) {
$day = '0' . $day;
}
$new_date = $day . '-' . $month[$month_num] . '-' . $year;
$new_date now should hold the date in the format you want.
$date = $year . '-' . $month . '-' . $day;
DATEformat provided by the database you are using. For example, MySQL
DATETIME,
DATE, and
TIMESTAMPvalues can be specified using any of a common set of formats, such as 'YYYY-MM-DD'. This is going to allow you to use the database's built-in
DATEfunctions down the road.
Substringing might be another option. As a matter of fact, if the database you are using has some feature-rich string functions, you could do it all in your SQL statement. An example, using MySQL:
SELECT
UPPER(CONCAT(
DATE_FORMAT(
CONCAT(
SUBSTRING_INDEX('1-12-2004','-',-1),
'-',
SUBSTRING_INDEX(SUBSTRING_INDEX('1-12-2004','-',2),'-',-1),
'-',
SUBSTRING_INDEX('1-12-2004','-',1)
),
'%d-%b-%y'
)
))
;
Just wanted to throw some other ideas at you today :)