Here you will get away with a character-by-character comparison as lexicographical order will match time order. Start at the left hand end of the string, stop when there's a mismatch - the larger digit at that point will be part of the string with the later timestamp value.
or as MarkT said… you could match from left to right…
byte diff ;
byte index ;
for (index=0; index < 11; index++) // look at each character of the time strings
{
diff = time[index] - now[index] ;
if (diff != 0)
break ; // stop at the first difference
}
if (diff == 0) // there where no differences
{
// times are the same
}
else if (diff < 0) // the first difference was now[index] > time[index]
{
// now > time
}
else if (diff > 0) // the first difference was now[index] < time[index]
{
// now < time
}
Makes good sense and thanks for the code example dafid.
I am now having problems with the way I am constructing my 'time' string.... from 4 vars using sprintf but I don't competely understand the syntax and I'm getting odd output? Any idea what I need to change to get the output from the code below to = "07:19:10:00"
So:
int date = 07
int hour = 19
int minute = 10
int second = 00
sprintf(time,"%02d_%02d_%02d_20%02d.dat",date, hour, minute, second);