Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #376 Date range for current month

Create list r and initialize it with the first date of the current month up to the last date of the current month.

import datetime
import calendar
today = datetime.date.today()
_, n = calendar.monthrange(today.year, today.month)
r = [today.replace(day=i) for i in range(1, n+1)]
require 'date'
today = Date.today
y, m = today.year, today.month
r = (Date.new(y, m, 1) .. Date.new(y, m, -1)).to_a

New implementation...
< >
steenslag