Results 1 to 5 of 5

Thread: Setting DefaultValue for Datetime

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    523

    Setting DefaultValue for Datetime

    In SQL Server Express (Visual Studio 2010), I would like to set the default datetime field to the creation date & time for the record. Numerous posts indicate I should set the DefaultValue in properties to GetDate(). But this throws an error "Property Value is not valid - The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Setting DefaultValue for Datetime

    Show us the insert statement. Have you created a default for the columns? Are you just doing this in the SQL Statement?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    523

    Re: Setting DefaultValue for Datetime

    I am not doing it in code. I am just trying to set it in the Properties using the 'View Designer' (shows the relational view with the tables and fields). I select the field, which is a datetime, and try to set the DefaultValue property.

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Setting DefaultValue for Datetime

    I don't use the UI I do this with SQL code in SSMS like this:

    sql Code:
    1. ALTER TABLE tableNameHere
    2.     ADD CONSTRAINT [df_SomeNameHere] DEFAULT (GETUTCDATE()) FOR [ColumnNameHEre];
    3. END
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    523

    Re: Setting DefaultValue for Datetime

    Thanks for the guidance. I know I can do it that way, but I would like to do it in the UI.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width