Date and Time Module

  Quality Thought is recognized as the best software testing institute in Hyderabad, offering top-notch training in manual testing, automation testing, and full stack testing tools. With a focus on industry-relevant curriculum and hands-on practice, Quality Thought prepares students for real-world software testing challenges. The institute provides expert-led training on popular tools and frameworks like Selenium, TestNG, Jenkins, Git, Postman, JIRA, Maven, and Cucumber, covering both frontend and backend testing essentials.


Quality Thought’s Full Stack Testing course is specially designed to make students proficient in both manual testing fundamentals and automated testing tools, along with exposure to API testing, performance testing, and DevOps integration. The institute stands out for its experienced trainers, live projects, placement support, and flexible learning options including classroom and online modes.


Whether you are a fresher aiming for a job or a working professional looking to upskill, Quality Thought offers customized learning paths. Its strong industry connections ensure regular placement drives and job interview

Date and Time Module 

Python provides the datetime module to work with dates and times easily and effectively. This module allows you to get the current date/time, format dates, do date arithmetic, and much more.


✅ Importing the Module

python

Copy

Edit

import datetime

📅 Get Current Date and Time

python

Copy

Edit

now = datetime.datetime.now()

print(now)

Output: 2025-06-27 10:15:45.123456


now() gives current date and time.


today() also gives current date (but as a date object).


🔢 Accessing Components

python

Copy

Edit

print(now.year)

print(now.month)

print(now.day)

print(now.hour)

📆 Creating Custom Date/Time

python

Copy

Edit

my_date = datetime.datetime(2025, 1, 1, 10, 30)

print(my_date)

📐 Date Formatting

python

Copy

Edit

print(now.strftime("%d-%m-%Y"))  # Output: 27-06-2025

print(now.strftime("%A"))        # Output: Friday

%d = Day, %m = Month, %Y = Year, %A = Day name


➕ Date Arithmetic

python

Copy

Edit

from datetime import timedelta


tomorrow = now + timedelta(days=1)

yesterday = now - timedelta(days=1)

print(tomorrow, yesterday)

🧾 Other Useful Classes

datetime.date: Only date (year, month, day)


datetime.time: Only time (hour, minute, second)


datetime.timedelta: Difference between two dates/times


✅ Uses

Logs & timestamps


Event scheduling


Countdown timers


Expiry date checks


Want this in Telugu or with examples as a project? Let me know!

Learn More

Functions in Python: Definition and Uses

Read More








Comments

Popular posts from this blog

What is Tosca and what is it used for?

Compute Engine (VMs)

What is Software Testing