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. Store neutral date in database

Store neutral date in database

Scheduled Pinned Locked Moved C#
databasehelptutorialquestionannouncement
4 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.
  • C Offline
    C Offline
    Casper Hansen
    wrote on last edited by
    #1

    Hello all I am building a website and I want to store the current time in a database, thats not a problem. But I also want to make the time format changable. For example if I have "May 2 2009" stored in the database and I decide I want to change the format to "5/2/2009", I need to either update the database or use a neutral date format that can be converted to the date format I want. Any tips on this? I thought about using timestamp, but cant rellay see where it fits in Thanks

    L 1 Reply Last reply
    0
    • C Casper Hansen

      Hello all I am building a website and I want to store the current time in a database, thats not a problem. But I also want to make the time format changable. For example if I have "May 2 2009" stored in the database and I decide I want to change the format to "5/2/2009", I need to either update the database or use a neutral date format that can be converted to the date format I want. Any tips on this? I thought about using timestamp, but cant rellay see where it fits in Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Just save the datetime in DateTime format in database, not in string.

      C 1 Reply Last reply
      0
      • L Lost User

        Just save the datetime in DateTime format in database, not in string.

        C Offline
        C Offline
        Casper Hansen
        wrote on last edited by
        #3

        What do you mean?

        L 1 Reply Last reply
        0
        • C Casper Hansen

          What do you mean?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          He means that a datetime is a number[^], and as such, is neutral. To quote; SQL Server uses 8 bytes to store the datetime data type. The first 4 bytes make up an integer value that represents the number of days since January 1, 1900. The second 4 bytes are an integer value that represents the number of milliseconds since midnight. When you send a date to the database, do you convert it to a string that get's included in your (text) command? If so, then you can get errors converting from/to the wrong format. If you send it as a number, then it will be interpreted as a "days past since date 1"-number. Try casting a date to float/integer, and see what happens :)

          I are troll :)

          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