"1/1/1900 12:00:00 AM" Date Problem in SQL Server 2005

  • In my application, there is one Datetime field. While saving if the date field is not selected it stores "1/1/1900 12:00:00 AM" in database. I want to store "NULL" [/i] instead. Please help me resolve this problem.

  • That is sql default behaviour. Make the column nullable and create a default constraint.

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • I have already kept the AllowNulls property of the Date column to True, but still it enters the 1/1/1900 12:00:00 AM in the database.

  • 1/1/1900 is 0 as a date. It means that either you're explicitly inserting the value 0 or '' into that column, or there's a default of 0 or '' on that column. Check both and ensure that the column is nullable, there's no default on it and you're not explicitly passing 0 or '' to it.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • In VB.net/ ASP.net when we use

    Dim BDate as Date

    its default value is 12:00:00 AM

    and while saving if the new date is not assigned to the BDate, then 1/1/1900 12:00:00 AM is stored in the database.

  • Cool - so you have identified the cause.

    Now you need to change the program so that it inserts a NULL instead - if your variable has not been assigned to.

    I'm no VB.NET expert, but using a variable which has not been assigned to seems less than ideal?

    Paul

  • aniket (6/27/2009)


    and while saving if the new date is not assigned to the BDate, then 1/1/1900 12:00:00 AM is stored in the database.

    So how are you doing the save to database?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 7 posts - 1 through 6 (of 6 total)

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