Jump to content

[SOLVED] Inserting todays date dd mm yy into a db


dmccabe

Recommended Posts

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?

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

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.

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.