What we are going to look at today is How To Get Current Date In Python We are going to be very clear about this topic. We hope that all the skepticism on this topic will be resolved through this article.
We will understand how to recover the current data of Python using various methods.
An important part of a database server, archived web logs, and app version that indicates the date and time a website or software or software was created.
More specifically, you’ll observe how to get:
- The non-formatted current date; and
- The formatted current date across different scenarios
Get non-formatted Current Date using Python
Here, We can get a non-formatted current date using the below source code.
import datetime Current_Date = datetime.datetime.today() print ('Current Date: ' + str(Current_Date))
At last, This is the output for your reference.
Current Date: 2021-09-30 08:55:49.890503
Get formatted Current Date using python
Here, We can get the formatted current date using the below program code.
import datetime Current_Date_Formatted = datetime.datetime.today().strftime ('%d%m%Y') print ('Current Date: ' + str(Current_Date_Formatted))
At last, This is the numbered output for the formatted current date.
Current Date: 30092021
Using strftime() method
datetime the object has a method for formatting date objects into readable strings.
The method is called
strftime(), and takes one parameter,
format, to specify the format of the returned string:
import datetime Current_Date_Formatted = datetime.datetime.today().strftime ('%d-%b-%Y') print ('Current Date: ' + str(Current_Date_Formatted))
Read Also: Tic Tac Toe Game In Python
Finally, This is the example output for your reference.
Current Date: 30-Sep-2021
We hope you find the How To Get Current Date In Python useful. And please let us know if you have any doubts about this article.