Блог

Python: выбрать даты текущей недели

#!/usr/bin/env python
# -*- coding: utf-8

from datetime import datetime

if __name__ == '__main__':
    today = datetime.today()
    year = int(today.strftime('%Y'))
    week = int(today.strftime('%W'))
 
    select = (
        datetime.strptime(
            "%d-%d-%d" % (year, week, 1),
            "%Y-%W-%w"),
        datetime.strptime(
            "%d-%d-%d" % (year, week, 0),
            "%Y-%W-%w")
     )
 
    print select