Format datestring correctly