none
Insert the current date/time into a table column as a default.

    Question

  • I want to insert a default datetime stamp of the the current date and time into a datetime column in a table when a new row is added.

    I added (getdate()) to the Default Value or Binding property for the RequestTime Column Name with datetime Data Type.

    What I get however when a new row is inserted in the table, rather than seeing the expected current date time, I see

    1/1/1900 12:18:12 AM   or 1/1/1900 12:00:00 AM

    What do I have to do to achieve the results I want.

    Thank you,

    -greg

     

    Thursday, November 06, 2008 10:09 PM

Answers

  • 1.Check your DB server date & time.

    2. Try with following SQL

     

    CREATE TABELE TEST1

    (EFNAME VARCHAR(20),

    ELNAME VARCHAR(20),

    LMDT DATETIME DEFAULT GETDATE())

     

    INSERT INTO TEST1(EFNAME,ELNAME)

    VALUES('R', 'RAJ')

     

    SELECT * FROM TEST1

    LMDT Column must show currect date & time.

    Friday, November 07, 2008 5:29 AM

All replies

  • 1.Check your DB server date & time.

    2. Try with following SQL

     

    CREATE TABELE TEST1

    (EFNAME VARCHAR(20),

    ELNAME VARCHAR(20),

    LMDT DATETIME DEFAULT GETDATE())

     

    INSERT INTO TEST1(EFNAME,ELNAME)

    VALUES('R', 'RAJ')

     

    SELECT * FROM TEST1

    LMDT Column must show currect date & time.

    Friday, November 07, 2008 5:29 AM
  • thank you. -g

     

    Friday, November 07, 2008 5:13 PM