Jump to content

Help with date format


lingo5

Recommended Posts

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

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];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.