ItSolutionStuff.com

How to Get Current Date in Python?

By Hardik Savani October 30, 2023
Python

Hi Dev,

This article will provide some of the most important example how to get current date in python. This article goes in detailed on python get current date. I explained simply step by step python get today's date. you will learn python get current date without time.

In this post, i will give you three examples to getting current date in python. we will use datetime module to get current date. so let's see following examples with output:

Example 1: Python Get Today's Date

main.py

from datetime import date
  
# Get Today's Date
today = date.today()
print("Today's date is :", today)

Output:

Today's date is : 2022-05-28

Example 2: Python Current Date with Different Formats

main.py

from datetime import date
  
today = date.today()
  
# dd/mm/YY
date1 = today.strftime("%d/%m/%Y")
print("date1 =", date1)
  
# Textual month, day and year	
date2 = today.strftime("%B %d, %Y")
print("date2 =", date2)
  
# mm/dd/y
date3 = today.strftime("%m/%d/%y")
print("date3 =", date3)
  
# Month abbreviation, day and year	
date4 = today.strftime("%b-%d-%Y")
print("date4 =", date4)

Output:

date1 = 28/05/2022
date2 = May 28, 2022
date3 = 05/28/22
date4 = May-28-2022

Example 3: Python Get the Current Date and Time

main.py

from datetime import datetime
  
# Current date and time object
now = datetime.now()
   
print("now() time =", now)
  
# dd/mm/YY H:M:S
currentDateTime = now.strftime("%d/%m/%Y %H:%M:%S")
print("Current Date and Time =", currentDateTime)	

Output:

now() time = 2022-05-28 09:29:52.455034
Current Date and Time = 28/05/2022 09:29:52

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube