0

Possible Duplicate:
PHP mysql insert date format

I'm trying to insert a date in to my mysql datebase. The problem is that when I for example try to save 2013-01-18 it saves it like this: 000-00-00.

$date = date("Y-m-d");
mysql_query("insert into events values('','$event','$notes','$date')");

What should I do to fix this?

Community
  • 1
  • 1
Johannes Flood
  • 735
  • 3
  • 7
  • 9
  • @sachleen: This isn't a dupe of that question; in this case, the OP is already doing my third suggestion (first option). – eggyal Jan 18 '13 at 23:09
  • Please show the output of `SHOW CREATE TABLE events`. It's likely that your columns are not in the same order as you are providing the values (and in particular, that the date is not the fourth column), which is why it's always best to explicitly name the columns in your `INSERT` statements. – eggyal Jan 18 '13 at 23:11

1 Answers1

0

It's better to convert it to Unix timestamp first, and then save the timestamp. It's a lot easier to sort etc.

As for your question: if you really want to save it that way, your column should be a 'varchar'.

Also, mysql_query is deprecated. Don't use that anymore, it won't be supported for long anymore.

Luc
  • 331
  • 3
  • 8