INSERT GetDate() into open table

  • Hiya,

    I have a table open in EM. Is there a way to enter a current timestamp into a datetime/smalldatetime field?

    Very much like CTRL-0 inserts NULL.

    TIA

     

  • TIA,

    There is no way I know of to automatically (unless anyone else knows better??) insert the current datetime in to a table open within EM unless the COLUMN has a default constraint set using the SQL getdate() function.

    Your other options are:

    - Write a SQL INSERT statement such as below which captures the current datetime using the getdate function:

    INSERT INTO tablename (column1, column2, datetimecolumn) VALUES('Value1', 'Value2', getdate())

    - Modify your table to have a default constraint set (as mentioned above):

    ALTER TABLE  tablename ADD CONSTRAINT 'constraintname' DEFAULT (getdate())

    It's worth noting that adding a constraint could have undue effects across the capture of dates and times within your database as if a datetime is not specified the current datetime will be captured by default.

    - Your last option is to be lazy and simply add the datetime in yourself in the correct format:

    30/03/2005 17:01:33

    Hope this helps,

    Lloyd

  • That's fine Lloyd. I'm fine with writing SQL or using constraints, I'm just lazy that's all.

    By the way, TIA is an acronymn, not my name!       (It stands for Thanks In Advance)

     

  • Ok no probs, my ALTER TABLE script was wrong, should have read:

    ALTER TABLE tablename 

      ADD CONSTRAINT 'constraintname' DEFAULT (getdate()) FOR 'columnname'

     

    Lloyd

  • Jamie,

    I knew I had this somewhere in my notes, and I found it this a.m.  Current Date should be CTRL-SemiColon; Current Time is CTRL-Shift-SemiColon (a.k.a. CTRL-Colon). 

    HTH - Linda

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply