Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I coudn't convert 4 bytes Hex value to datetime format.

FA 5B 04 00 = 31.12.2020 18:00
F9 5B 04 00 = 31.12.2020 17:00
E1 05 03 00 = 30.06.2011 17:00
21 06 03 00 = 01.07.2011 09:00

I think first change to Float or Int32 - Little Endian (DCBA), then convert float to datetime.
But i did't get true value.

I have files which have stock datas. I want to read and write new datas.
There are different files for different periods.
Each of row in files has 32 bytes.
Each data has 7 columns.
Each column is 4 bytes.
I solved others except <datetime> first 4 bytes.
The others are Float - Little Endian (DCBA) format.
Columns:
<datetime><open><high><low><close><size><vol>

Files to be used:

Orginal 60 minutes data file :
orjinal_min60.60 - Google Drive[^]

Real values 60 minutes file:
realValues_min60.csv - Google Drive[^]

Hex file 60 minutes:
min60Hex.txt - Google Drive[^]

Orjinal 1 minute file:
orginal_min1.01 - Google Drive[^]

Real values 1 minute file:
realValues_min01.csv - Google Drive[^]

Hex file 1 minute:
min1Hex.txt - Google Drive[^]

What I have tried:

byte[] byteValue = someValue;
long longVar = BitConverter.ToInt64(byteValue);
DateTime dateTimeVar = DateTime.FromBinary(longVar);
Posted
Updated 3-Feb-21 3:36am
v4
Comments
Richard MacCutchan 3-Feb-21 5:40am    
Where do these values come from? That may give a clue to their correct values.
kelzi 3-Feb-21 9:38am    
I added source files.
Richard MacCutchan 3-Feb-21 11:30am    
But that tells us nothing, since we have no idea what any of these fields are, or how to decode them. You need to go back and talk to whoever produces this data and ask them how to interpret the date fields.

At a guess - and that's all it can be from two so similar samples - it looks a bit silly.
The only difference between the two values is one hex digit - a "9" changes to a "A" while the resulting date changes by one hour - which would imply that the least significant digit of the first byte is the hour. Which is silly, because that doesn't leave a lot for minutes ...

I'd start by doing two things: firstly find the specification of exactly what the encoding of the date / time element into the binary data is meant to be. Most are either a "raw encode" or more commonly an elapsed period since a particular point in time (ticks, seconds, minutes ... whatever works for the resolution the design required).
Secondly, find a wider range of values to check your code against: 1st Jan 1970 @ 00:00, 31st December 2001 @ 23:59, your DOB, your next birthday ... a wide ranging sample of values.

Then start looking at translating - but guessing from two near-identical samples is a recipe for major errors!
 
Share this answer
 
v2
Comments
kelzi 3-Feb-21 3:18am    
I understood. I think first byte is not hour.
More examples:

E1 05 03 00 30.06.2011 17:00
21 06 03 00 01.07.2011 09:00
Just a guess:
FA 5B 04 00 = 31.12.2020 18:00
F9 5B 04 00 = 31.12.2020 17:00
E1 05 03 00 = 30.06.2011 17:00
21 06 03 00 = 01.07.2011 09:00
    ^ this look like the month - 1

Need more samples and details, where does it come from ?
Try couples of samples where only 1 thing vary, Day, Month, Year, Hour.
 
Share this answer
 
Comments
kelzi 3-Feb-21 9:37am    
I added source files.
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900