Say I have two types of datetime format need to check which are the following:
%Y-%m-%dT%H:%M:%S.%f%z
%Y-%m-%d
and convert them to this format %Y-%m-%d %H:%M:%S UTC
.
My code at the moment only manage to check one condition :
if val is None:
val2 = val
else:
val2 = datetime.strptime(val, '%Y-%m-%dT%H:%M:%S.%f%z').__format__("%Y-%m-%d %H:%M:%S UTC")
My pseudocode will be :
if val is None:
val2 = val
elif val is in "%Y-%m-%d" format:
do this --> val2 = convert from "%Y-%m-%d" to "%Y-%m-%d %H:%M:%S UTC" (eg: 2020-09-01 00:00:00 UTC)
else:
val2 = datetime.strptime(val, '%Y-%m-%dT%H:%M:%S.%f%z').__format__("%Y-%m-%d %H:%M:%S UTC")
The time format will be 00:00:00 UTC
constantly because there is no timestamp specified in the first place.