Help with Date Time formatting and comparison

  • Thread starter Thread starter David
  • Start date Start date
D

David

I have an application that stores the time information received via the
serial port from some hardware.

The application needs to compare this time gainst the time received in the
last packet and see if the difference is greater than a timeout period that
is stored in a database record for that hardware.

The data comes in as bytes that are packed BCD values in 24 hour format. ie.
2:15:00 pm would be received as 14h 15h 00h

Firstly, is there a simple way to turn the incoming data from the databuf
into a string ? In C I can just add a null character to the buffer and
select the start position like mystr = databuf + 3

Secondly, what would be the most efficient way of converting this into a
time only value that could be stored in the database and easily compared to
the next value + timeout period.

ie. Process needs to do this.

if TimeValue in received packet > Lastsaved Time + Timeout period then do
something
Lastsaved time = timevalue in this packet

Thanks heaps
 
David,

The datetime is for me the best format to handle dates. Avoid any string
comparising because that is direct culture dependend.

dim mydate as datetime = new datetime(year,mont,day,hour,minutes,seconds)

Gives an for every culture proper date and is when used together with the
timespan very good for comparing.

I hope this helps?

Cor
 
Back
Top