Python add minutes to timestamp
The title says it all. I am writing a script to make scheduled GET requests to an API. I want to print when the next API call will be made, which would be 15 minutes from the previous call. Show I'm very close, but have been running into the following error: Here's my code:
I can get things to work (sort of) when changing the following line:
However, this prints a timestamp with six decimal places for milliseconds. I want to keep things in the
Seanny123 8,02312 gold badges65 silver badges118 bronze badges asked Apr 3, 2017 at 19:17
philiporlandophiliporlando 8814 gold badges18 silver badges28 bronze badges 1 You don't need to use
answered Apr 3, 2017 at 19:24
0 You can achieve it just by using timestamp instead:
The output I got was:
answered Apr 3, 2017 at 19:33
Joab MendesJoab Mendes 1,00018 silver badges32 bronze badges Close. There is no need to use
In other words, pass the answered Apr 3, 2017 at 19:24
roganjoshroganjosh 12k4 gold badges29 silver badges44 bronze badges 2 As soon as I asked this question I found out what I was doing wrong... For those who are curious, here is the solution:
answered Apr 3, 2017 at 19:24
philiporlandophiliporlando 8814 gold badges18 silver badges28 bronze badges How do you add minutes to a timestamp in Python?Add minutes to a timestamp in Python using timedelta. Step 1: If the given timestamp is in string format, then convert it to the datetime object using datetime. ... . Step 2: Create an object of timedelta, to represent an interval of N minutes. ... . Step 3: Add the timedelta object to the datetime object created in step 1.. How do I add minutes to a datetime?Use the timedelta() class from the datetime module to add minutes to datetime, e.g. result = dt + timedelta(minutes=10) . The timedelta class can be passed a minutes argument and adds the specified number of minutes to the datetime.
How do I add hours and minutes to a date in Python?Use the timedelta() class from the datetime module to add hours to datetime, e.g. result = dt + timedelta(hours=10) . The timedelta class can be passed a hours argument and adds the specified number of hours to the datetime.
Can you add time in Python?Use the timedelta() class from the datetime module to add time to datetime, e.g. result = dt + timedelta(hours=2, minutes=25, seconds=24) .
|