1

I have two values, this value is hexadecimal-binary value. I need to convert into timestamp and get difference between two values. I tried many ways but not success. Can you please help me?

value1 = b'\x05\x03' and value2 = b'c\xf3'

I tried this way:

import struct

data= type(b'\xb5B')
index1= 773
index2= 62307

date1 = bin(773)
date2= bytes(date1, 'ascii')

print(datetime.datetime.fromtimestamp(int(index1)).strftime('%Y-%m-%d %H:%M:%S'))
print(datetime.datetime.fromtimestamp(int(index2)).strftime('%Y-%m-%d %H:%M:%S'))

date1 = datetime.datetime.fromtimestamp(index1).strftime('%d-%m-%y -%h')
date2= datetime.datetime.fromtimestamp(index2)

unpacked, = struct.unpack('<Q', date2)
test= datetime.datetime(1601,1,1) + datetime.timedelta(microseconds=unpacked/10.)

print(test)
print(date2)
Mark
  • 90,562
  • 7
  • 108
  • 148
  • Welcome to Stack Overflow. For the specified values of `index1` and `index2`, what should the result be? According to what logic? I'm confused by the code you're showing because I don't know whether it represents one attempt to solve the problem or multiple attempts, and also because I don't understand whether `index1` and `index2` each represent a separate date, or whether they represent a single date when combined, or just what. We can only help you solve problems that are actually explained. Please read [ask]. – Karl Knechtel Aug 21 '21 at 02:41

0 Answers0