0

I would LIKe to know how to set a specific DateTime timestamp using the DateTime module in python. For example if I want ... To happen on 1 August 2022. How can I make a DateTime timestamp that will hold that date. Thanks for all help in advance

Zapperz
  • 1
  • 1

2 Answers2

0

You can construct a new datetime object with your date (and optionally with time) and then call timestamp() on it. For example, you can do:

from datetime import datetime

timestamp = datetime(2022, 8, 1).timestamp()
# timestamp is now 1659304800.0

You can find the official documentation here.

l0drex
  • 16
  • 4
0

To create a date, we can use the datetime() class (constructor) of the datetime module.

The datetime() class requires three parameters to create a date: year, month, day.

Example

Create a date object:

import datetime

x = datetime.datetime(2020, 5, 17)

print(x)

source

Luka Banfi
  • 111
  • 8