14

I am trying to get the timestamp of monday at 00:00 of the current week in python. I know that for a specific date, the timestamp can be found using

baseTime = int(datetime.datetime.timestamp(datetime.datetime(2020,1,1)))

However, I want my program to automatically find out, based on the date, which date monday of the current week was, and then get the timestamp. That is to say, it would return different dates this week and next week, meaning different timestamps.

I know that the current date can be found using

import datetime
today = datetime.date.today()

Thanks in advance

Aleks
  • 378
  • 1
  • 3
  • 10
  • You can use below program after importing datetime and timedelta from datetime today = datetime.now().date() monday = today - timedelta(days = today.weekday()) – Sadique Khan Apr 12 '23 at 03:15

1 Answers1

43

I am trying to get the timestamp of monday at 00:00 of the current week in python

You could use timedelta method from datetime package.

from datetime import datetime, timedelta
now = datetime.now()
monday = now - timedelta(days = now.weekday())
print(monday)

Output

2020-01-27 08:47:01
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128