datetime % strftime now is now allocatable (variable length) character and does not need to be trimmed on return. Cleaned up the code a bit for better readability.