Guidance Forums / Rapid-Q Basic / From hex string to date?

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. From hex string to date?
Posted by: 2005-08-26 14:29:32
I have an hexadecimal string representing microseconds elapsed since AD 0; how can I convert it to current Date? Does it exist a ready-made RapidQ source?
I probably could convert that string to another string representing seconds elapsed since 1/1/1970, which is a more commonly used format,but I still have the problem of messing with leap yeras, different-length months and so on...

Example of "0 AD"-based string:
00E0D1E0F6FB1DDE = [2005-04-19 19:42:09]
see , use this string to convert: '[] (16'00E0D1E0F6FB1DDE)/1000000

Same string, 1970-based:
3FB50ED94AD12 (= decimal 70046870751953)

How can I obtain [2005-04-19 19:42:09] from this mess of numbers?!?
Message2. Re: From hex string to date?
Posted by: 2005-09-03 08:20:40
1.start by converting the whole string to a decimal format AND dividing by 1000 (you only want whole seconds), save the resulting value (let's call it DT)

2. divide the result by 31557600 and round off to get the year

3. DT - year*31557600 gives you a remainder (call it PY)

4. the remainder of PY / 60 gives you the seconds (S)

5. the remainder of (PY - S) / 60 gives minutes (M)

6. the remainder of (PY - M*60 - S)/3600 gives hours

7. calculate the number of whole days left over (WD). Use an array with the days of the months summed (adding 1 day to the total for MARCH - first day of - in a leapyear) to quickly find the month by going DOWN the array and subtracting the total from WD; if there is a positive result (>0) you've found the month. The leftover is the day of the month.
Message3. Re: From hex string to date?
Posted by: 2005-09-03 08:26:13
on leapyears; every 4th year is a leapyear, every 100th year is NOT a leapyear, every 400th year IS a leapyear.

the value 31557600 is slightly off I'm afraid, as its just 365.25 x 24 x 60 x 60, instead of 365.25 you have to use a SLIGHTLY different value; 365.2422

so use 31556926.08 instead of 31557600 !!!
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Thu 2017-6-29  Guidance Laboratory Inc. Hits:0