469,167 Members | 1,150 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

mySQL datetime field default now() fails

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 19 '05 #1
6 51700
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 19 '05 #2
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 19 '05 #3
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 19 '05 #4
"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 19 '05 #5
"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 19 '05 #6
"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 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Phil Powell | last post: by
7 posts views Thread by Tony Clarke | last post: by
reply views Thread by M. Bader | last post: by
2 posts views Thread by Marcos Rodríguez | last post: by
1 post views Thread by Mike the Canadian | last post: by
2 posts views Thread by Ryan | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.