Friday, July 24, 2026
HomeLanguagesDate Time Expression (dte) module in python

Date Time Expression (dte) module in python

In this article, we will discuss how to process and work with dates and time using the Python in command line. Python provides dte module for the same. This module has the following features – 

  • It recognizes english month, week and locale names.
  • It works in the highest unit appearing first – 2021 – 12 -24 ( yyyy-MM-dd ).

Installation 

This module does not come built-in with Python. To install this type the below command in the terminal

pip install dte
pip install appdirs

Example 1: Working with Dates

  • T: today
  • YD: yesterday
  • TM: tomorrow
  • N: now

Working with Dates

Example 2: Working with Time

Playing with Time

Example 3: Working with Weekdays

Demonstrating Weekdays

Note: dow Takes unix timestamp and returns the day of week corresponding to it.

In Keyword 

It serves two purposes. Converts time formats, like today in seconds. Also converts point of time in Unix timestamp.

Example usage – in operator

Working with extremities

In this, we use ‘last’ operator to get the date of last weekday from current time.

Syntax : dte last [weekday]

Working of last

Working with operators

The dte library supports addition and subtraction of dates, even some comparison operations like – 

  • + : Adds dates.
  • – : Takes difference of dates and stores delta.
  • <, <=, >, ==, != : compares two points in time and returns a boolean.

Example: 

Examples of using operators

Working with deltas

delta is a time delta object made by chaining of [number + unit] together without spaces.

Example:

Working with delta

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6902 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6971 POSTS0 COMMENTS