Catalin
Catalin

Reputation: 13

Set today date to Default Value or Binding

I'm using MSSQL2008. The date type is Date, and I would like to set the default date to now or today.

I've tried GETDATE(), but I get "Error validating the default for column 'Date'". If I persist with GETDATE(), it doesn't work.

Upvotes: 1

Views: 2039

Answers (3)

LukeH
LukeH

Reputation: 269348

GETDATE returns a DATETIME that you can subsequently CAST to the DATE type:

CAST(GETDATE() AS DATE)

Upvotes: 0

Kris Ivanov
Kris Ivanov

Reputation: 10598

are you sure that you are setting Date in the correct place? according to your error message it looks like the column name is Date, not the type; make sure the type is Date and try again, GETDATE() as a default should work fine

Upvotes: 1

Raymund
Raymund

Reputation: 7892

How about

convert(varchar, getdate(), 103)

Upvotes: 0

Related Questions