By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,930 Members | 633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,930 IT Pros & Developers. It's quick & easy.

mySQL datetime field default now() fails

P: n/a
I have a mySQL database table with a column field datatype of datetime that
I set up in the original create table statement like this:

create table nnet_usermetadata (
....
nnet_record_entered datetime default 'now()'
)

However, upon execution, each time a record is entered into
nnet_usermetadata the results are:

00-00-0000 00:00:00

Is there a way I can always ensure that the current date and time are always
entered into the datetime field?

Phil
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Phil Powell <so*****@erols.com> wrote:
I have a mySQL database table with a column field datatype of datetime
that I set up in the original create table statement like this:

create table nnet_usermetadata (
...
nnet_record_entered datetime default 'now()'
)


Hi Phil,

Why not using a timestamp? It is updated every time the record is updated.

nnet_record_entered timestamp(14) NOT NULL

HTH;
JOn
Jul 16 '05 #2

P: n/a
"Phil Powell" <so*****@erols.com> wrote in message news:<YzF6b.130543$xf.73825@lakeread04>...
I have a mySQL database table with a column field datatype of datetime that
I set up in the original create table statement like this:

create table nnet_usermetadata (
...
nnet_record_entered datetime default 'now()'
)

However, upon execution, each time a record is entered into
nnet_usermetadata the results are:

00-00-0000 00:00:00

Is there a way I can always ensure that the current date and time are always
entered into the datetime field?


You could declare that column as TIMESTAMP. Then, when you insert NULL
value in it, it will insert the current date and time.
The format is a little different, instead pf 05-05-2003 17:15:13 it
will be 20030505171513.
If you wish to keep the DATETIME declaration, you could let the
application calculate the current date/time and then insert the
achieved value.

Bart
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.