Python Get Current Date in YYYY-MM-DD Format

Python

Nicesnippets

463

07-10-2021


Hello Friends,

Now let's see example of how to get current date in python. I am going to show you python get current date in yyyy-mm-dd format. We will learn get current date in python.

The datetime module is supplies classes for manipulating dates and dates. This article will give you example of get current date in python.

Here I will give two example for how to get current date in python. I am use datetime and time module to get current date in yyyy-mm-dd. So let's see the below example:

Example 1


import time

// get current date in yyyy-mm-dd format

currentDate = time.strftime("%Y-%m-%d")

print(currentDate)

Output:

16:06:41

Example 2

from datetime import datetime

// get current date and time

currentTimeDate = datetime.now()

// get only date in yyyy-mm-dd format

currentDate = currentTimeDate.strftime('%Y-%m:%d')

print(currentDate)

Output:

16:06:41

It will help you....