Python Get Current Date And Time Example Tutorial
Published On: 25/08/2022 | Category:
Python

Hi Guys,
Here, I will show you how to works python get current date and time. if you have question about python get today's date and time then I will give simple example with solution. I explained simply step by step python get current date and time without time. this example will help you python get today's date and time without time.
In this post, i will give you three examples to getting current date and time in python. we will use datetime module to get current date and time. so let's see following examples with output:
So let's see bellow example:
Example 1: Python Get Today's Date main.pyfrom datetime import date # Get Today's Date today = date.today() print("Today's date is :", today)Output:
Today's date is : 2022-08-25Example 2: 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-08-25 04:41:33.261422 Current Date and Time = 25/08/2022 04:41:33Example 3: 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 = 25/08/2022 date2 = Aug 25, 2022 date3 = 08/25/22 date4 = Aug-25-2022
It will help you....