Modified to work with datetime - Thanks Leeroy