Not sure what is wrong with your Perl code. However since you are using MySQL, this may be "re-inventing a wheel" as there is a function called DayName() in MySQL. Since you seem confident that the MySQL DATETIME is right, consider just asking MySQL to do the DayName conversion.