Python Forum
add next day date in time.struct_time object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
add next day date in time.struct_time object
#2
The following from: https://pymotw.com/3/datetime/

Date math uses the standard arithmetic operators.
datetime_date_math.py

import datetime

today = datetime.date.today()
print('Today    :', today)

one_day = datetime.timedelta(days=1)
print('One day  :', one_day)

yesterday = today - one_day
print('Yesterday:', yesterday)

tomorrow = today + one_day
print('Tomorrow :', tomorrow)

print()
print('tomorrow - yesterday:', tomorrow - yesterday)
print('yesterday - tomorrow:', yesterday - tomorrow)
This example with date objects illustrates using timedelta objects to compute new dates, and subtracting date instances to produce timedeltas (including a negative delta value).

Output:
$ python3 datetime_date_math.py Today : 2017-07-30 One day : 1 day, 0:00:00 Yesterday: 2017-07-29 Tomorrow : 2017-07-31 tomorrow - yesterday: 2 days, 0:00:00 yesterday - tomorrow: -2 days, 0:00:00
Reply


Messages In This Thread
RE: add next day date in time.struct_time object - by Larz60+ - Feb-22-2018, 07:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 294 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Date Time Series Help...Please spra8560 2 418 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Python date format changes to date & time 1418 4 694 Jan-20-2024, 04:45 AM
Last Post: 1418
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 1,110 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  Formatting a date time string read from a csv file DosAtPython 5 1,398 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  Review my code: convert a HTTP date header to a datetime object stevendaprano 1 2,060 Dec-17-2022, 12:24 AM
Last Post: snippsat
  Wait til a date and time KatManDEW 2 1,466 Mar-11-2022, 08:05 PM
Last Post: KatManDEW
  Date format and past date check function Turtle 5 4,365 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  How to add previous date infront of every unique customer id's invoice date ur_enegmatic 1 2,274 Feb-06-2021, 10:48 PM
Last Post: eddywinch82
  Naming the file as time and date. BettyTurnips 3 3,044 Jan-15-2021, 07:52 AM
Last Post: BettyTurnips

Forum Jump:

User Panel Messages

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