dmccabe Posted June 5, 2008 Share Posted June 5, 2008 I am trying to capture todays date and put it in to a field called requested_date in a mysql db. $requested_date = date("d/m/y"); This works as I have echo'd $requested_date and see the correct date and format. However when inserting it in to the db I get this: Error: Incorrect date value: '' for column 'requested_date' at row 1 The datebase field "requested_date" has a field type of DATE, is this correct? or what is wrong? Link to comment https://forums.phpfreaks.com/topic/108820-solved-inserting-todays-date-dd-mm-yy-into-a-db/ Share on other sites More sharing options...
xoligy Posted June 5, 2008 Share Posted June 5, 2008 For date i used the NOW() function //when posting $query = "INSERT INTO news (`title`, `author`, `post`, `date`, `time`) VALUES ('$title', '$name', '$post', NOW(), '$time')"; //retrival $query = "SELECT `id`, `title`, `author`, `post`, DATE_FORMAT(`date`, '%M %D, %Y') as `date`, TIME_FORMAT(`time`, '%H:%i') as `time` FROM `news` ORDER BY `time` AND `date` DESC LIMIT 5"; thats what i used on my newpage thing Link to comment https://forums.phpfreaks.com/topic/108820-solved-inserting-todays-date-dd-mm-yy-into-a-db/#findComment-558182 Share on other sites More sharing options...
Gamic Posted June 5, 2008 Share Posted June 5, 2008 date in mysql is 'yyyy-mm-dd' (todays date would be 2008-06-05). Link to comment https://forums.phpfreaks.com/topic/108820-solved-inserting-todays-date-dd-mm-yy-into-a-db/#findComment-558186 Share on other sites More sharing options...
jesushax Posted June 5, 2008 Share Posted June 5, 2008 just change the field value to varchar and set a lenght of about 10 should be fine, less hassle Link to comment https://forums.phpfreaks.com/topic/108820-solved-inserting-todays-date-dd-mm-yy-into-a-db/#findComment-558195 Share on other sites More sharing options...
kev wood Posted June 5, 2008 Share Posted June 5, 2008 i had problems when setting my field in the table to varchar so i changed it to DATETIME and it worked fine. the problem i was getting was that it would only ever put 2008 in the field no matter how long i set the varchar to be. spoke to a few people and they said that it was strange it was doing that and it should have stored all the information in. Link to comment https://forums.phpfreaks.com/topic/108820-solved-inserting-todays-date-dd-mm-yy-into-a-db/#findComment-558201 Share on other sites More sharing options...
dmccabe Posted June 5, 2008 Author Share Posted June 5, 2008 I put it as VARCHAR as I am not planning on using the value for anything other than to read. Thanks guys Link to comment https://forums.phpfreaks.com/topic/108820-solved-inserting-todays-date-dd-mm-yy-into-a-db/#findComment-558222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.