How To Get Current Date In Python

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
How To Get Current Date In Python

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))

Output

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))

Output

At last, This is the numbered output for the formatted current date.

Current Date: 30092021

Using strftime() method

The 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

Output

Finally, This is the example output for your reference.

Current Date: 30-Sep-2021

Final Thoughts

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.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment