Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. LINQ DateTime Format

LINQ DateTime Format

Scheduled Pinned Locked Moved C#
csharpquestiondatabasesql-serverlinq
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    u2envy12
    wrote on last edited by
    #1

    Im converting all code from ADO.net to LINQ. In ADO i could add a DateTime field into SQL when adding a record. Im doing the same with LINQ & im getting an error. SqlDateTime Overflow. Must be between 1/1/1753 12:00:00 AM AND 12/31/9999 11:59:59 PM. My format is 2008/11/03 11:00:00 AM. How can I make it take this format & store it in sql server as the required format & not throw this error ?

    G 1 Reply Last reply
    0
    • U u2envy12

      Im converting all code from ADO.net to LINQ. In ADO i could add a DateTime field into SQL when adding a record. Im doing the same with LINQ & im getting an error. SqlDateTime Overflow. Must be between 1/1/1753 12:00:00 AM AND 12/31/9999 11:59:59 PM. My format is 2008/11/03 11:00:00 AM. How can I make it take this format & store it in sql server as the required format & not throw this error ?

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      There is no standard date format that looks like that. Try the ISO 8601 format "2008-11-03 11:00:00" instead. Otherwise you would have to use the DateTime.ParseExact method with the date format "yyyy/MM/dd HH:mm:ss" to parse the string into a DateTime value.

      Despite everything, the person most likely to be fooling you next is yourself.

      U 1 Reply Last reply
      0
      • G Guffa

        There is no standard date format that looks like that. Try the ISO 8601 format "2008-11-03 11:00:00" instead. Otherwise you would have to use the DateTime.ParseExact method with the date format "yyyy/MM/dd HH:mm:ss" to parse the string into a DateTime value.

        Despite everything, the person most likely to be fooling you next is yourself.

        U Offline
        U Offline
        u2envy12
        wrote on last edited by
        #3

        Thx Guffa I found the problem. A DateTime null in link is not a null in sql. I was only passing one DateTime value & thinking the other DateTime will be null. I passed both DateTime values & no error.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups