Today now in this article i will provide you some of the most important example how we can get current date in python. So in this article goes in detailed on python get the current date. Now i will explained simply step by step python get today’s date. From here you will learn about python get current date without time.
So in this post, i will give you total three examples to getting the current date in python. Here i will use datetime module to get the current date.
So let’s start and see the following examples:
Example 1: Python Get Today’s Date
from datetime import date # Get Today's Date today = date.today() print("Today's date is :", today)
Example 2: Python Current Date with Different Formats
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)
Example 3: Python Get the Current Date and Time
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)
Read Also: How to Get Current Year in Python?
Thanks for read. I hope it help you. For more you can follow us on facebook