I have a mysql database with field type "TIME" for the days of the week, both open and close for all 7 days.
my table looks like HOURSSUNSTART (TIME) HOURSSUNSTOP (TIME) ...
I have a form thats generated in PHP with the hours in regular time format such as 12:00 AM and 12 PM, before inserting a record to the db I call a function which converts 12:00AM to 00:00:00 and so on.
However my values are off in the db, they are all off by + or - 12 hours. I know my function in PHP works fine because I tested it and the right values were being generated. Is there something that has to be done before enter a time into mysql, do we have to specify its 24 hour format.
It seems liek my function is wrong but it works fine.
Oh yea, if I sub in a hard coded time like 23:00:00 instead of a dynamic value then it goes into the db just fine.
this is really weird.
Here is the function:
and here is where I write the query
restaurantfields is an array containing strings of "12:00 AM" or "12:00PM" etc...
my table looks like HOURSSUNSTART (TIME) HOURSSUNSTOP (TIME) ...
I have a form thats generated in PHP with the hours in regular time format such as 12:00 AM and 12 PM, before inserting a record to the db I call a function which converts 12:00AM to 00:00:00 and so on.
However my values are off in the db, they are all off by + or - 12 hours. I know my function in PHP works fine because I tested it and the right values were being generated. Is there something that has to be done before enter a time into mysql, do we have to specify its 24 hour format.
It seems liek my function is wrong but it works fine.
Oh yea, if I sub in a hard coded time like 23:00:00 instead of a dynamic value then it goes into the db just fine.
this is really weird.
Here is the function:
Code:
function convert_time($time){
switch (trim($time)) {
case "12:00 AM":
return "00:00:00";
break;
case "12:30 AM":
return "00:30:00";
break;
case "1:00 AM":
return "01:00:00";
break;
case "1:30 AM":
return "01:30:00";
break;
case "2:00 AM":
return "02:00:00";
break;
case "2:30 AM":
return "02:30:00";
break;
case "3:00 AM":
return "03:00:00";
break;
case "3:30 AM":
return "03:30:00";
break;
case "4:00 AM":
return "04:00:00";
break;
case "4:30 AM":
return "04:30:00";
break;
case "5:00 AM":
return "05:00:00";
break;
case "5:30 AM":
return "05:30:00";
break;
case "6:00 AM":
return "06:00:00";
break;
case "6:30 AM":
return "06:30:00";
break;
case "7:00 AM":
return "07:00:00";
break;
case "7:30 AM":
return "07:30:00";
break;
case "8:00 AM":
return "08:00:00";
break;
case "8:30 AM":
return "08:30:00";
break;
case "9:00 AM":
return "09:00:00";
break;
case "9:30 AM":
return "09:30:00";
break;
case "10:00 AM":
return "10:00:00";
break;
case "10:30 AM":
return "10:30:00";
break;
case "11:00 AM":
return "11:00:00";
break;
case "11:30 AM":
return "11:30:00";
break;
case "12:00 PM":
return "12:00:00";
break;
case "12:30 PM":
return "12:30:00";
break;
case "1:00 PM":
return "13:00:00";
break;
case "1:30 PM":
return "13:30:00";
break;
case "2:00 PM":
return "14:00:00";
break;
case "2:30 PM":
return "14:30:00";
break;
case "3:00 PM":
return "15:00:00";
break;
case "3:30 PM":
return "15:30:00";
break;
case "4:00 PM":
return "16:00:00";
break;
case "4:30 PM":
return "16:30:00";
break;
case "5:00 PM":
return "17:00:00";
break;
case "5:30 PM":
return "17:30:00";
break;
case "6:00 PM":
return "18:00:00";
break;
case "6:30 PM":
return "18:30:00";
break;
case "7:00 PM":
return "19:00:00";
break;
case "7:30 PM":
return "19:30:00";
break;
case "8:00 PM":
return "20:00:00";
break;
case "8:30 PM":
return "20:30:00";
break;
case "9:00 PM":
return "21:00:00";
break;
case "9:30 PM":
return "21:30:00";
break;
case "10:00 PM":
return "22:00:00";
break;
case "10:30 PM":
return "22:30:00";
break;
case "11:00 PM":
return "23:00:00";
break;
case "11:30 PM":
return "23:30:00";
break;
}
}
and here is where I write the query
Code:
"INSERT INTO `HOURS` (`HOURSSUNSTART` , `HOURSSUNSTOP` ,
`HOURSMONSTART` , `HOURSMONSTOP` ,
`HOURSTUESSTART` ,`HOURSTUESSTOP` , `HOURSWEDSTART` , `HOURSWEDSTOP` ,
`HOURSTHURSTART` , `HOURSTHURSTOP` , `HOURSFRISTART` ,
`HOURSFRISTOP` , `HOURSSATSTART` , `HOURSSATSTOP` ,)
VALUES ('convert_time($restaurantfields[20]',
'convert_time($restaurantfields[21])',
'convert_time($restaurantfields[22])',
'convert_time($restaurantfields[23])',
'convert_time($restaurantfields[24])',
'convert_time($restaurantfields[25])',
'convert_time($restaurantfields[26])',
'convert_time($restaurantfields[27])',
'convert_time($restaurantfields[28])',
'convert_time($restaurantfields[29])',
'convert_time($restaurantfields[30])',
'convert_time($restaurantfields[31])',
'convert_time($restaurantfields[32])',
'convert_time($restaurantfields[33])')";