Найти - Пользователи
Полная версия: Вопрос по дате
Начало » Python для новичков » Вопрос по дате
1
Kanat
Привет ето знает,
есть в python такая функция указываешь месяц ,функция возвращает первый и последний день?
s0rg
День недели? Год при этом не указывается?
Kanat
s0rg
День недели? Год при этом не указывается?
Нужно получить первый и помследний день формат не имеет значения..
что то не могу найти….в делфи такое есть
s0rg
Не сталкивался с делфи.
Вам нужно что-то такое:
#!/usr/bin/env python
#-*- coding: utf8 -*-

from datetime import date, timedelta

def get_first_last(month, year=None):
"""
Get first and last day of month
if year is None - current year is used
Return tuple (first, last)
"""
if year is None:
year = date.today().year
fst = date(year, month, 1)
lst = fst.replace(month=month+1) - timedelta(days=1)
return (fst, lst)

print get_first_last(1)
Output: (datetime.date(2011, 1, 1), datetime.date(2011, 1, 31))
?
pyuser
from calendar import monthrange
print(monthrange(year, month))
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB