Date Type /phpMyAdmin

Hello,
I want to make it so that in my table when a row gets inserted I want to have the date of insert, this cannot change anymore.
In phpMyAdmin I set it to
Field: date
Type: date
attributes:
Null: Yes

But this sets the date to 0000-00-00.

Can someone please tell me how to?

Thanks

The value 0000-00-00 is the default value for the date in a MySQL database. When entering a date, using the command curdate(), the date will show up in the database in the year-month-day format. Hence the 0000-00-00

:slight_smile:

waht do u use if you have got a datetime field in ur db… ?

beachball

Originally posted by beachball
waht do u use if you have got a datetime field in ur db… ?

NOW() or CURRENT_TIMESTAMP. same thing.

format for date is:

date DATE NOT NULL

then you should not get 0000-00-00

Sarah :smiley:

Originally posted by Sarah
[B]format for date is:

date DATE NOT NULL

then you should not get 0000-00-00

Sarah :smiley: [/B]

True, that slipped my mind for a moment :D.

its only fresh in my mind because I am setting up my first db and tables at present - but that has worked no probs with me. and you don’t want users to input a date as you can get into all sorts of hassles then!

Sarah :stuck_out_tongue:

Yep, I will be using the date-function as well in a database, I first have to set up some other functions and make sure they work, and then I will certainly shut of that default, I don’t like it :D.

Originally posted by Sarah
[B]format for date is:

date DATE NOT NULL

then you should not get 0000-00-00

Sarah :D[/B]

what are you talking about? of course you will still get 0000-00-00 if the column is NOT NULL. 0000-00-00 IS NOT NULL. if the col wasn’t NOT NULL, the value would be NULL if you didn’t specify a value.

get it?

It was more in line with using CURDATE() and the format for the db rather than not null etc…

As the case was George was getting 0000-00-00 and hence that was what we were trying to resolve DATE NOT NULL is the correct syntax for the date field so its always filled in - if you use CURDATE() tell me how you can get 0000-00-00? I’m interested to know?!

ok, i understand what you’re sayin. but, you said the format was “date DATE NOT NULL”. he didn’t need to know that, he already had the column declared right (except it was NULL) and he only wanted to know how to insert the date.

your post implied that you won’t get 0000-00-00 if the col is NOT NULL, which isn’t true.

yes, if you always use CURDATE() you won’t get 0000-00-00… BUT you won’t get NULL either. so therefore the column does not need to be NOT NULL. in some cases you may want/need it to be able to be NULL if your app needs to differentiate between no value and 0000-00-00.