I suspect the code above could all be made a whole bunch easier by use of strptime() in place of sscanf(). YMMV, though.