lingo5 Posted December 13, 2009 Share Posted December 13, 2009 Hi, I have a record update form that shows Start date and End date in 2 separate fields like dd/mm/yyyy. When I edit the dates they do not get to the database correctly, all I get is 0000/00/00. I guess this is because the date format accepted by MySQL is yyyy/mm/dd. I'm stuck because I don't know how to convert the dates back to MySQL format for updating. This is my update query.(AG_fechai and AG_fechaf are the start and end dte fields) I appreciate your help. Thanks. // $updateSQL = sprintf("UPDATE t_agenda SET AG_fechai=%s, AG_fechaf=%s, AG_precio=%s, AG_horario=%s, AG_titulo_esp=%s, AG_titulo_eng=%s, AG_titulo_ger=%s, AG_titulo_fra=%s WHERE id_AG=%s", GetSQLValueString($_POST['AG_fechai'], "date"), GetSQLValueString($_POST['AG_fechaf'], "date"), GetSQLValueString($_POST['AG_precio'], "text"), GetSQLValueString($_POST['AG_horario'], "text"), GetSQLValueString($_POST['AG_titulo_esp'], "text"), GetSQLValueString($_POST['AG_titulo_eng'], "text"), GetSQLValueString($_POST['AG_titulo_ger'], "text"), GetSQLValueString($_POST['AG_titulo_fra'], "text"), GetSQLValueString($_POST['id_AG'], "int")); mysql_select_db($database_amat_connect, $amat_connect); $Result1 = mysql_query($updateSQL, $amat_connect) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/184983-help-with-date-format/ Share on other sites More sharing options...
cags Posted December 13, 2009 Share Posted December 13, 2009 You are right about the reason, because it expects YYYY-MM-DD your date is invalid so it will insert the default. You just need to re-arrange it. There are lots of ways of doing it. $parts = explode("/", $date); $date = $parts[2] . "-" . $parts[1] . "-" . $parts[0]; Link to comment https://forums.phpfreaks.com/topic/184983-help-with-date-format/#findComment-976517 Share on other sites More sharing options...
lingo5 Posted December 13, 2009 Author Share Posted December 13, 2009 Hi cags, thanks for your reply. I am new to PHP so I would appreciate a bit more detail if possible. How do I apply that code to my query and where?. Sorry but I am still trying to learn. Thanks Link to comment https://forums.phpfreaks.com/topic/184983-help-with-date-format/#findComment-976521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.