jeffrydell Posted August 25, 2007 Share Posted August 25, 2007 I have a date in a variable - supposedly formatted properly for MySQL's date field type. (YYYY-MM-DD). When I attempt to insert a new record in a table, the date doesn't store properly. $sql = "INSERT INTO `dogs` (`owner_id`, `callname`, `breed`, `sex`, `birthdate`, `height`, `accessid`, `accesstype`) VALUES ($oid, '$nm', '$brd', '$sex', '$dt2snd', '$ht', $aid, '$atyp')"; ... always ends up with the birthdate field reading '0000-00-00', whether I put quotes on the $dt2snd or not. Any suggestions on what to do or where to 'read up'? Link to comment https://forums.phpfreaks.com/topic/66664-solved-mysql-insert-and-dates/ Share on other sites More sharing options...
dani9990 Posted August 25, 2007 Share Posted August 25, 2007 you need to define your date before you insert it $date = date('Y-m-d, H-i-s'); Link to comment https://forums.phpfreaks.com/topic/66664-solved-mysql-insert-and-dates/#findComment-333988 Share on other sites More sharing options...
pocobueno1388 Posted August 25, 2007 Share Posted August 25, 2007 you need to define your date before you insert it $date = date('Y-m-d, H-i-s'); It doesn't look like they are wanting that format. Do this instead: $date = date("Y-m-d"); Show us where you give a value to your variable $dt2snd. Also, you need to have single quotes around all your variables in the query. Link to comment https://forums.phpfreaks.com/topic/66664-solved-mysql-insert-and-dates/#findComment-333989 Share on other sites More sharing options...
jeffrydell Posted August 25, 2007 Author Share Posted August 25, 2007 Plain & simple (to avoid any confusion), $dt2snd is a string. The string is formatted as 2007-08-25. If I explicitly include a fixed value in a MySQL INSERT statement, the value goes in to the record just fine, but when I reference a variable which is a string formatted exactly the same way, I get 0000-00-00 in the record. The question is, do I need to do anything to a string which is formatted according to the MySQL date 'format' in order to be able to put that variable's value into the record being inserted? Link to comment https://forums.phpfreaks.com/topic/66664-solved-mysql-insert-and-dates/#findComment-334101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.