mySQL datetime field default now() fails

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Powell

    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_usermetada ta (
    ....
    nnet_record_ent ered datetime default 'now()'
    )

    However, upon execution, each time a record is entered into
    nnet_usermetada ta 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


  • Jon Kraft

    #2
    Re: mySQL datetime field default now() fails

    Phil Powell <soazine@erols. com> wrote:
    [color=blue]
    > 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_usermetada ta (
    > ...
    > nnet_record_ent ered datetime default 'now()'
    > )[/color]

    Hi Phil,

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

    nnet_record_ent ered timestamp(14) NOT NULL

    HTH;
    JOn

    Comment

    • Bart Van der Donck

      #3
      Re: mySQL datetime field default now() fails

      "Phil Powell" <soazine@erols. com> wrote in message news:<YzF6b.130 543$xf.73825@la keread04>...[color=blue]
      > 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_usermetada ta (
      > ...
      > nnet_record_ent ered datetime default 'now()'
      > )
      >
      > However, upon execution, each time a record is entered into
      > nnet_usermetada ta 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?[/color]

      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

      Comment

      Working...