Stripping Times From Date/Times when the Time is 00:00
To strip an empty time (00:00) from a date/time string, use the following function:
defstrip_zero_time_from_date(indate):
# Strip zero time from timestamp
if indate[8:12] == "0000":
return indate[:8]
return indate
Here are examples of code that uses this function:
value = strip_zero_time_from_date('200802280000') # value is now 20080208
value = strip_zero_time_from_date('200802281225') # value is still 200802281225