Home > Enterprise >  Python date time without hyphens
Python date time without hyphens

Time:09-24

I would line to print today date but without the hyphens.

Right now if I use

today = str(datetime.now().date())
print(today)

I get this format:

2021-09-23

what I would like to see is this

20210923

I tried to use

.strftime("%YYYY %M %d")

But nothing, nothing seems to work. Can please somebody help me to understand what am I doing wrong?

CodePudding user response:

This is what you want:

from datetime import date

print(date.today().strftime("%Y%m%d"))

Output:

20210923

  • Related