Date int64 in C++/VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmn001
    New Member
    • Dec 2009
    • 5

    Date int64 in C++/VB

    Im reading data from a VB random file.

    In C++ the 8 byte __int64 value is: 467476252661173 4528

    The actual date is: 26/03/1990
    The dateticks value found in VB is : 627740064000000 000

    I am trying to find the date or dateticks value from the C++ value using C++ only.

    Im assuming the int64 value correlates somehow to the dateticks, but as you can see, the int64 value is much larger than the dateticks value.
    I have read: http://msdn.microsoft.com/en-us/libr...6e(VS.80).aspx
    but I have no idea what to do.. Any help is much appreciated. Thanks,

    Regards,

    Dave

    (The following date code in VB works:
    Public datum As Date
    VB6.Format(Data Record.date, "YYYY-MM-DD") )
    Last edited by dmn001; Dec 20 '09, 08:20 PM. Reason: added more info.
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    Where did you get 467476252661173 4528 and 627740064000000 000?

    Comment

    • dmn001
      New Member
      • Dec 2009
      • 5

      #3
      467476252661173 4528 is the __int64 or Int64 representation of the data.
      627740064000000 000 is the dateticks representation of the data.

      In VB they can be found using something like:

      Dim datum as Int64

      Dim e as Date(1990, 3, 26) '(using the Date Data type in VB)
      Console.WriteLi ne(e)
      Dim datetick As Int64
      datetick = e.Ticks
      Console.WriteLi ne(datetick)

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        I would guess that the most likely cause is that you are reading the wrong 8 bytes from the file to make you 64 bit integer.

        Comment

        • dmn001
          New Member
          • Dec 2009
          • 5

          #5
          Good guess, but im using VB to read both the int64 and date to get the same results above, so it is the same 8 bytes.

          There is some conversion that happens when declaring a variable as Date type, so it is a matter of finding how to convert an __int64 to Date ticks, then to date type or date format. This is because C++ doesn't have the Date type.

          Either this, or my other idea is to abandon this and write a exe in VB to convert the required data, and use the C++ to call the program. Probably much easier to do that way, but I thought the problem of the conversion to date type was simpler than it is.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Y9ou are using C++ to read a file created by VB, you think you know where the data is stored but the value you read back bears no resemblance to the value you are expecting.

            Personally my next step would be to open the file in a hex editor and locate the data manually.

            Comment

            • dmn001
              New Member
              • Dec 2009
              • 5

              #7
              Using VB i read the same int64 and date from the same region of memory to get the same results as I repeated above.

              Comment

              • weaknessforcats
                Recognized Expert Expert
                • Mar 2007
                • 9214

                #8
                But did you use a hex editor?

                If you don't have one, use the debug window for memory and fish out the bits. Windows is Big Endian.

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  Yes but that isn't really what I was driving at. You are still reading the single piece of the file you believe is correct rather than looking at the whole file and seeing if you can identify the data that you wish to read from the file.

                  That is you haven't looked at the whole file and found with-in it the correct location of the data you require, you have still read from what you believe is the correct location but got a value that is clearly incorrect.

                  I say again, get a hex editor and examine the file by hand.

                  Comment

                  • dmn001
                    New Member
                    • Dec 2009
                    • 5

                    #10
                    Thanks for your feedback. I do not understand hex very well.

                    I have attached a sample VB project which opens the file included, and outputs the date, the int64 and dateticks values. The goal is, given the int64 values, I would like to convert these to dateticks values. (assuming I am reading from the right int64 values in the first place). Please could you take a look. Thanks.

                    Regards,

                    Dave
                    Attached Files

                    Comment

                    Working...