Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
datetime module question
#8
(Oct-12-2023, 11:01 AM)jacksfrustration Wrote: i want to make a list of days and dates for the current month
(Oct-12-2023, 02:37 PM)jacksfrustration Wrote: Is there a way to ... display the past 5 and upcoming 5 days
these are fairly different requiremets
You can easily generate dates between t-5 and t=5
from datetime import date, timedelta

def dates(offset=5):
    tday = date.today()
    for delta in range(-offset, offset+1):
        yield (tday + timedelta(days=delta)).strftime('%a %d %B %Y')

print(list(dates()))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
datetime module question - by jacksfrustration - Oct-12-2023, 11:01 AM
RE: datetime module question - by menator01 - Oct-12-2023, 12:43 PM
RE: datetime module question - by jacksfrustration - Oct-12-2023, 02:37 PM
RE: datetime module question - by buran - Oct-12-2023, 01:39 PM
RE: datetime module question - by jacksfrustration - Oct-12-2023, 02:27 PM
RE: datetime module question - by menator01 - Oct-12-2023, 04:38 PM
RE: datetime module question - by deanhystad - Oct-12-2023, 06:31 PM
RE: datetime module question - by buran - Oct-12-2023, 07:10 PM
RE: datetime module question - by agmoraojr - Jan-12-2024, 01:24 AM
RE: datetime module question - by deanhystad - Jan-12-2024, 04:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Module not found question sighhhh12 0 1,643 Sep-09-2022, 05:43 AM
Last Post: sighhhh12
  Question on subprocess module. knoxvilles_joker 3 2,872 Apr-11-2021, 12:51 AM
Last Post: knoxvilles_joker
  keyboard module question DPaul 0 2,251 Mar-23-2021, 04:22 PM
Last Post: DPaul
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str' findbikash 2 9,935 Sep-18-2019, 08:32 AM
Last Post: buran
  Module googletrans 2.4.0 Question hlhp 0 2,698 Jun-17-2019, 03:50 PM
Last Post: hlhp
  Question about the Random Module Exsul 1 2,081 Mar-13-2019, 02:06 AM
Last Post: ichabod801
  Problem with datetime module PierreSoulier 3 9,477 Jul-24-2018, 11:03 AM
Last Post: perfringo
  Python Module Question ATXpython 9 9,736 Oct-09-2016, 12:59 AM
Last Post: ATXpython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020