CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    25

    Hex value to date time

    Hi,
    I a hex value 0x00009B9300E313F9 whose equivalent date time value is
    Jan 16 2009 13:46:45.950 .i got this hex value after raw reading an .mdf file of sql server 2000
    the sql datatype of this value is "datetime"
    can somebody please help me convert this hex value to date-time using c++

    thanks

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Hex value to date time

    Convert the hex value to a __uint64 and pass it to the constructor of COleDateTime.

  3. #3
    Join Date
    Jan 2009
    Posts
    25

    Re: Hex value to date time

    thanks for replying,

    I tried using Coledatetime in following manner : -

    LONGLONG t = 0x00009B9300E313F9;

    //t = 171055677379577(decimal value)


    CString buffer;
    SYSTEMTIME st;
    FILETIME FileTime;

    FileTime.dwLowDateTime = (DWORD) t;
    FileTime.dwHighDateTime = (DWORD)(t >> 32);

    FileTimeToSystemTime(&FileTime,&st);

    COleDateTime* startOnDate = new COleDateTime(st);

    buffer = startOnDate->Format(_T("%d-%b-%Y"));


    It gives me o/p as 17-Jul-1601 where as it should be Jan 16 2009

    the datetime value as viewed in hex editor is f913e300 939b0000 i converted it
    in little endian form to get 00009B9300E313F9.

    What can i do next?

  4. #4
    Join Date
    Apr 2003
    Posts
    1,755

    Re: Hex value to date time

    The 4 bytes of the sql datetime is the number of days since 1900-1-1. The second 4 bytes is the miliseconds since midnight. You can convert the values like this
    Code:
       int date_part = 0x00009B93;
       int time_part = <time value here> / 1000;   
       COleDateTime startOnDate(1900, 1, 1, 0, 0, 0);
       startOnDate += COleDateTimeSpan(date_part, 0, 0, time_part);
       CString buffer = startOnDate.Format();
    The location of the date 0x00009B93 is ok but your time should be the next 4 bytes after the days location. Check your .mdf file and use the 4 bytes after 0x00009B93 as time.

    Hope it will help

  5. #5
    Join Date
    Jan 2009
    Posts
    25

    Re: Hex value to date time

    hi thanks for replying and for sharing these useful information.

    The date part is giving me the right ans which is 16-01-2009
    however the time is still incorrect.
    the 4 bytes associated with time is 0x00e313f9 (little endian form).
    The time should be 1:46PM where as i am getting the ans as 4:08:01 AM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured