# Getting today”s date in YYYY-MM-DD in Python?

| | | | | | |

👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!

I"m using:

``````str(datetime.datetime.today()).split()[0]
``````

to return today"s date in the `YYYY-MM-DD` format.

Is there a less crude way to achieve this?

👻 Read also: what is the best laptop for engineering students?

How do I calculate the date six months from the current date using the datetime Python module?

By Eef

I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?

The reason I want to generate a date 6 months from the current date is to produce a review date. If the user enters data into the system it will have a review date of 6 months from the date they entered the data.

478

I found this solution to be good. (This uses the python-dateutil extension)

``````from datetime import date
from dateutil.relativedelta import relativedelta

six_months = date.today() + relativedelta(months=+6)
``````

The advantage of this approach is that it takes care of issues with 28, 30, 31 days etc. This becomes very useful in handling business rules and scenarios (say invoice generation etc.)

``````\$ date(2010,12,31)+relativedelta(months=+1)
datetime.date(2011, 1, 31)

\$ date(2010,12,31)+relativedelta(months=+2)
datetime.date(2011, 2, 28)
``````

We hope this article has helped you to resolve the problem. Apart from Getting today”s date in YYYY-MM-DD in Python?, check other code Python module-related topics.

Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.

By the way, this material is also available in other languages:

Walter Danburry

Texas | 2023-03-29

Maybe there are another answers? What Getting today”s date in YYYY-MM-DD in Python? exactly means?. I am just not quite sure it is the best method

Olivia Gonzalez

Moscow | 2023-03-29

Thanks for explaining! I was stuck with Getting today”s date in YYYY-MM-DD in Python? for some hours, finally got it done 🤗. I just hope that will not emerge anymore

Chen Krasiko

Milan | 2023-03-29

Thanks for explaining! I was stuck with Getting today”s date in YYYY-MM-DD in Python? for some hours, finally got it done 🤗. Will get back tomorrow with feedback

## Shop

Learn programming in R: courses

\$FREE

Best Python online courses for 2022

\$FREE

Best laptop for Fortnite

\$399+

Best laptop for Excel

\$

Best laptop for Solidworks

\$399+

Best laptop for Roblox

\$399+

Best computer for crypto mining

\$499+

Best laptop for Sims 4

\$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries