How to Get Current Day in Python?

Aug 10, 2022

.

Admin

How to Get Current Day in Python?

Hi Dev,

This tutorial will give you example of Python Get Current Day Example. you can understand a concept of Python Get Today Day. Here you will learn Python Get Current Day. We will look at example of How to Get Current Day in Python.

In this post,i will give you two examples to getting current year in python. we will use datetime module to get current year from date.

so let's see following examples with output:

Example: 1


main.py

from datetime import datetime

today = datetime.now()

print("Current Date and Time :", today)

print("Current Day :", today.day)

Output:

Current Date and Time : 2022-05-02 09:33:51.346666

Current Day : 02

Example: 2

main.py

from datetime import datetime

today = datetime.now()

day1 = today.strftime("%d")

print("Current Day with zero :", day1);

day2 = today.strftime("%-d")

print("Current Day :", day2);

Output:

Current Day with zero : 02

Current Day : 2

#Python