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
#1
Hi all,

I need your help with my code. I want to add the next day date using with time.struct_time object, but I have got no idea how to do this after I have stored the string in the self.epg_time_1 list.

Example:

time.struct_time(tm_year=2018, tm_mon=2, tm_mday=22, tm_hour=17, tm_min=00, tm_sec=0, tm_wday=3, tm_yday=53, tm_isdst=-1)
To this:

time.struct_time(tm_year=2018, tm_mon=2, tm_mday=23, tm_hour=17, tm_min=00, tm_sec=0, tm_wday=3, tm_yday=53, tm_isdst=-1)
If I want to add the next day, I would have to readd the same code that I have already been using:

epg_time_1_days = time.strftime("%d")
epg_time_1_months = time.strftime("%m")
epg_time_1_year = time.strftime("%Y")
epg_time_1_days = int(time.strftime("%d") + 1)
epg_time_1_days = str(today_day)
epg_time_1_months = str(epg_time_1_months)
epg_time_1_year = str(epg_time_1_year)
half_hour_date = str(epg_time_1_days + "/" + epg_time_1_months + "/" + epg_time_1_year + " " + "17:30PM")
self.epg_time_1.append(half_hour_date)
Here is the code:

half_hour_date = ''.join(str(x) for x in self.epg_time_1)
epg_time_1 = time.strptime(half_hour_date, '%d/%m/%Y %I:%M%p')
Output for half_hour_date:

22/02/2018 5:00PM
Output for epg_time_1:

[python]time.struct_time(tm_year=2018, tm_mon=2, tm_mday=22, tm_hour=17, tm_min=00, tm_sec=0, tm_wday=3, tm_yday=53, tm_isdst=-1)
I don't want to re-add the same code that I have already wrote it. If you can show me an example how I could use a short simple code to add the date to the next day date using with time.struct_time object, that would be great.

Thanks in advance
Reply


Messages In This Thread
add next day date in time.struct_time object - by chris0147 - Feb-22-2018, 05:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 255 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Date Time Series Help...Please spra8560 2 382 Feb-01-2024, 01:38 PM
Last Post: spra8560
  Python date format changes to date & time 1418 4 628 Jan-20-2024, 04:45 AM
Last Post: 1418
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 1,060 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  Formatting a date time string read from a csv file DosAtPython 5 1,306 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  Review my code: convert a HTTP date header to a datetime object stevendaprano 1 2,014 Dec-17-2022, 12:24 AM
Last Post: snippsat
  Wait til a date and time KatManDEW 2 1,442 Mar-11-2022, 08:05 PM
Last Post: KatManDEW
  Date format and past date check function Turtle 5 4,290 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,246 Feb-06-2021, 10:48 PM
Last Post: eddywinch82
  Naming the file as time and date. BettyTurnips 3 3,001 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