datetime C# equvalent
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: datetime C# equvalent

  1. #1
    Join Date
    Feb 2009
    Posts
    12

    datetime C# equvalent

    I have the following table column
    Code:
    [hire_date] [datetime] NOT NULL DEFAULT (getdate()),
    Then using Linq I try the following

    employee e1 = new employee
    {
    .....
    hire_date = new DateTime()
    };

    And I get this error:
    Code:
    SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
    What is the C# equivalent for MSSQL datatime database type ?

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: datetime C# equvalent

    I don't think there is one. I normally set a static global variable to the "1753" date and just use that when instantiating dates.

  3. #3
    Join Date
    Feb 2009
    Posts
    12

    Re: datetime C# equvalent

    Quote Originally Posted by eclipsed4utoo View Post
    I don't think there is one. I normally set a static global variable to the "1753" date and just use that when instantiating dates.
    like this
    new Datetime("1973") ?

  4. #4
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: datetime C# equvalent

    no, like

    Code:
    Convert.ToDateTime("1/1/1753 12:00:00 AM");

  5. #5
    Join Date
    Feb 2009
    Posts
    12

    Re: datetime C# equvalent

    Thank you.

  6. #6
    Join Date
    Feb 2009
    Location
    Atlanta, GA
    Posts
    17

    Re: datetime C# equvalent

    DateTime maps to SQL's datetime, but the valid range is different. To initialize a DateTime with the minimum value use:
    System.Data.SqlTypes.SqlDateTime.MinValue.Value

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center