I'm creating a function that returns the time. I wanted it to display am/pm instead of having a max of 24h. So I needed to first substract 6 on the hour if it is above 12.
But nothing is happening, I'm not even getting an error and I have no idea what is the cause for this. Can someone explain what is the cause?
import datetime
MONTHS = 'jan feb mar apr may jun jul aug sep oct nov dec'.upper().split(' ')
def get_date():
# 01-OCT-1978 04:31:17
date = datetime.datetime.today().__str__().split(' ')
date[0] = date[0].split('-')
if int(date[1].split(':')[0]) > 12:
date[1].split(':')[0] = str(int(date[1].split(':')[0]) - 12)
real_date = date[0][2] + '-' + MONTHS[int(date[0][1])] + '-' + date[0][0] + ' ' + date[1].split('.')[0]
return real_date
print(get_date())
# 07-APR-2021 21:56:12