For a certain date (this is a hard coded date), I want to increment through the time for LastModifiedTimeFrom
and LastModifiedTimeTo
by 10 minutes each time.
I have tried the below but it is not performing the increment and I am not sure why?
Date d = Date.parse("HH:mm:ss", "00:00:00")
Calendar c = Calendar.getInstance()
c.setTime(d)
c.add(MINUTE, 10)
assert c.time == "00:10:00"
c.add(MINUTE, 10)
assert c.time == "00:20:00"
c.add(MINUTE, 10)
assert c.time == "00:30:00"
For adding time with 20 minutes increments:Enter formula =A1+TIME(0,20,0) into the Formula Bar, and then press the Ctrl + Enter key simultaneously.
Another simple technique to calculate the duration between two times in Excel is using the TEXT function: Calculate hours between two times: =TEXT(B2-A2, "h") Return hours and minutes between 2 times: =TEXT(B2-A2, "h:mm") Return hours, minutes and seconds between 2 times: =TEXT(B2-A2, "h:mm:ss")
I would recommend a combo approach of using some Groovy syntactic sugar and the verbose, but ever-reliable Java Calendar. With the code below, you should be able to parse in a date and start adding 10 minutes to it, checking it as you go along.
import java.util.Calendar
import static java.util.Calendar.*
Date d = Date.parse("HH:mm:ss", "00:00:00")
Calendar c = Calendar.getInstance()
c.setTime(d)
c.add(MINUTE, 10)
assert c.time.format("HH:mm:ss") == "00:10:00"
c.add(MINUTE, 10)
assert c.time.format("HH:mm:ss") == "00:20:00"
c.add(MINUTE, 10)
assert c.time.format("HH:mm:ss") == "00:30:00"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With