Answers for "find out current datetime in python"

37

python current date

from datetime import date

today = date.today()
print("Today's date:", today)
Posted by: Guest on April-15-2020
1

find out current datetime in python

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)

Outputs:

d1 = 16/09/2019
d2 = September 16, 2019
d3 = 09/16/19
d4 = Sep-16-2019
Posted by: Guest on February-03-2022
2

how to get current date in python

from datetime import date
current_date = date.today()
print("today's date is ",current_date))
Posted by: Guest on October-03-2021
1

how to get current date and time in python

date_and_time = datetime.now()
print("The today current date and time is:- ",date_and_time)
Posted by: Guest on October-03-2021

Code answers related to "find out current datetime in python"

Python Answers by Framework

Browse Popular Code Answers by Language