- Get link
- X
- Other Apps
Current Date in Python
Hello Programmers!
In this tutorial, I will teach you how to get the current date in python. This is an advanced topic of python. If you have any questions then you can comment below. So, let's get started.
Example-1: Get current Date Using Python
from datetime import date
today = date.today()
print(today)
Here we imported the date class from the datetime module. Then we used the method date.today() to get the current date and store it in the toady variable. Then we printed the current date.
Example-2:Currentdate date in different formats
from datetime import date
today = date.today()
# dd/mm/YY
d1 = today.strftime("%d/%m/%Y")
print("d1 =", d1)
# Textual month, day and year
d2 = today.strftime("%B %d, %Y")
print("d2 =", d2)
# mm/dd/y
d3 = today.strftime("%m/%d/%y")
print("d3 =", d3)
# Month abbreviation, day and year
d4 = today.strftime("%b-%d-%Y")
print("d4 =", d4)
Output:
d1 = 30/12/2020
d2 = December 30, 2020
d3 = 12/30/20
d4 = Dec-30-2020
Congratulations! Now you know how to print the current date in python. Printing the current date was a very advanced topic of python. Now, you can easily print the current date in python.
If you want to print the current time then you can read this article ---> https://pythonproramming.blogspot.com/2020/12/how-to-get-current-time-in-python.html.
Happy Coding :)
how to get current date and time in python,current date and time in python,display current date and time in python,how to get current date in python,h
Comments
Post a Comment