This is an old problem that I thought I had fixed. I hadn't thought about months with 2 digits in them like Nov and Dec.
I'm trying to convert a month submitted as a string into a decimal equivalent.
Drew10 suggested the following fix
switch(substr(strtolower($_POST['month_stats']), 0, 3)) {
case "jan": $month_decimal = 1; break;
case "feb": $month_decimal = 2; break;
case "mar": $month_decimal = 3; break;
case "apr" : $month_decimal = 4; break;
case "may": $month_decimal = 5; break;
case "jun" : $month_decimal = 6; break;
case "jul" : $month_decimal = 7; break;
case "aug": $month_decimal = 8; break;
case "sep": $month_decimal = 9; break;
case "oct" : $month_decimal = 10; break;
case "nov": $month_decimal = 11; break;
case "dec": $month_decimal = 12; break;
}
which I adapted to my needs as follows:
switch($_POST['month_stats'])
{
case "January": $month_decimal = 01; break;
case "February": $month_decimal = 02; break;
case "March": $month_decimal = 03; break;
case "April" : $month_decimal = 04; break;
case "May": $month_decimal = 05; break;
case "June" : $month_decimal = 06; break;
case "July" : $month_decimal = 07; break;
case "August": $month_decimal = 08; break;
case "September": $month_decimal = 09; break;
case "October" : $month_decimal = 10; break;
case "November": $month_decimal = 11; break;
case "December": $month_decimal = 12; break;
}
The allocated numbers - 01, 02, etc isn't being allocated to the $month_decimal variable so when I use the $month_decimal variable in the query it becomes 6 instead of 06 for each of the single digit dates.
Any ideas how (or why) the allocated values for the $month_decimal are being interpreted as single digits or how I can fix it?