Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to get the Python date object for last Wednesday?
You can get the Python date object for last wednesday using some Python date math. Whatever the day of the week it is today, subtracting 2 from it and taking the modulus of the result by 7 will give us how back was wedenesday.
example
from datetime import date from datetime import timedelta today = date.today() offset = (today.weekday() - 2) % 7 last_wednesday = today - timedelta(days=offset)
Output
This will give you the output −
2017-12-27
Advertisements
