-
March 5th, 2009, 01:00 PM
#1
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
-
March 5th, 2009, 01:08 PM
#2
Re: Hex value to date time
Convert the hex value to a __uint64 and pass it to the constructor of COleDateTime.
-
March 5th, 2009, 01:46 PM
#3
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?
-
March 5th, 2009, 10:35 PM
#4
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
-
March 6th, 2009, 06:30 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|