How do I create a default date value for a field?

  • Hey guys I have a question. Below I'm showing two basic date functions that can easily be applied as the default value of a field in a Microsoft Access table. Is it possible to do the exact same thing in a SQLServer table? And if so what would the fuctions look like? Any help you can provide would be appreciated. 

    As they appear in an Access table.

    Field EffectiveDate default value:  is Date()-(DatePart("d",Date()))

    Field PostDate default value is: Date()

  • Hello Anthony,

    The default in SQL Server are as follows:

    Field PostDate default value is: Date()

    which equals Getdate()

    and

    Field EffectiveDate default value: is Date()-(DatePart("d",Date()))

    which equals Getdate()-(DatePart(d, Getdate()))

    Thanks and have a great day!!!


    Lucky

  • For defaults, the SQL Server equivalent of now() is GetDate() and the equivalent of date() is (convert(datetime,floor(convert(float,getdate()))))

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil, thank you for helping me with this. You guys are really outstanding in the way your willing to give assistance!  

  • lucky, the same goes for you man. Were it not for you guys I'd be stuck. 

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

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