Why is my default date always getting set to 1900-01-01 00:00:00.000

How do i set my default value for a datetime column to be null and not 1900-01-01 00:00:00.000?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Reza RadConsultant, TrainerCommented:
set your column as nullable,
Guy Hengel [angelIII / a3]Billing EngineerCommented:
how did you define the default value?

you must allow nulls, and say NULL as default value, not "0" or "" or something like that.
Reza RadConsultant, TrainerCommented:
alter table Blah alter column blahblah float null
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Webbo_1980Author Commented:
My column is nullable but My default value is ((0))

Is this the cause of the problem?
Just define the column to allow NULLs, and the default value will be NULL.  

ie  CREATE TABLE SomeTable ( StringCol varchar(50), DateTimeCol datetime NULL)
     INSERT INTO SomeTable ( StringCol ) VALUES ('Test1')

    Test1      |   NULL

> Why is my default date always getting set to 1900-01-01 00:00:00.000

    Most commonly, it can happen if you insert a value like "0" or an empty string "".
    Both of those values are implicitly converted to the date 1900-01-01 00:00:00.000

   INSERT INTO SomeTable ( StringCol, DateTimeCol ) VALUES ('Test2', '')
   INSERT INTO SomeTable ( StringCol, DateTimeCol ) VALUES ('Test2', 0)

Test2      | 1900-01-01 00:00:00.000
Test2      | 1900-01-01 00:00:00.000
> My default value is ((0))
> Is this the cause of the problem?

   Yes. MS SQL will convert 0 to 1900-01-01 00:00:00.000.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>but My default value is (NULL)
Reza RadConsultant, TrainerCommented:
you must set default value to NULL instead of 0
set default value to null for ur datimetime column,it must help u
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.