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. Datetime to integer conversion and vice versa

Datetime to integer conversion and vice versa

Scheduled Pinned Locked Moved C#
7 Posts 5 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.
  • H Offline
    H Offline
    H he el el oooo
    wrote on last edited by
    #1

    If i want to convert system date to int , what should i do and also if i try to convert the int to the datetime i should get the same date as before

    ItsMe

    A C 2 Replies Last reply
    0
    • H H he el el oooo

      If i want to convert system date to int , what should i do and also if i try to convert the int to the datetime i should get the same date as before

      ItsMe

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Are you expecting to use a standard int conversion, such as one returned from a C++ API, or do you want to make your own ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      M 1 Reply Last reply
      0
      • H H he el el oooo

        If i want to convert system date to int , what should i do and also if i try to convert the int to the datetime i should get the same date as before

        ItsMe

        A Offline
        A Offline
        aamironline
        wrote on last edited by
        #3

        You can not convert DateTime object to Int32 but yes you can convert it to Double using ToOADate() method. To generate DateTime object from Double you can use DateTime.FromOADate() method... For Example Double d = DateTime.Now.ToOADate(); ... DateTime.FromOADate(d); Hope this helps you out...

        M Aamir Maniar aamirOnline.com

        M 1 Reply Last reply
        0
        • C Christian Graus

          Are you expecting to use a standard int conversion, such as one returned from a C++ API, or do you want to make your own ?

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          M Offline
          M Offline
          madhusri
          wrote on last edited by
          #4

          any thing is fine but it must work in c# if i give system.datetime.now i must be able to convert to integer and again back to datetime.

          Thanks and Regards Madhu

          C 1 Reply Last reply
          0
          • A aamironline

            You can not convert DateTime object to Int32 but yes you can convert it to Double using ToOADate() method. To generate DateTime object from Double you can use DateTime.FromOADate() method... For Example Double d = DateTime.Now.ToOADate(); ... DateTime.FromOADate(d); Hope this helps you out...

            M Aamir Maniar aamirOnline.com

            M Offline
            M Offline
            madhusri
            wrote on last edited by
            #5

            i want to be converted to int only

            Thanks and Regards Madhu

            D 1 Reply Last reply
            0
            • M madhusri

              i want to be converted to int only

              Thanks and Regards Madhu

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              Then you need to decide what representation you want to use. THe old 32bit datetime format from C only supports the range 1970 to ~2038(?). If you need a larger range you'll have to loose some precision at the seconds end of the values.

              1 Reply Last reply
              0
              • M madhusri

                any thing is fine but it must work in c# if i give system.datetime.now i must be able to convert to integer and again back to datetime.

                Thanks and Regards Madhu

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                Well, you realisitically need to invent some way of representing it then. Do you need the time, or just the date. An int is 16 bit, so 0x00000000, you could use one byte for month, one for day and two for year. Or, you could set a base date, and store the date as days from that date. There's all sorts of options.

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                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