A very stupid question today: How do I use DateInterval? I want to do a countdown. If I use
dim d as new DateInterval(0, 0, 0, 1, 0, 0, 0)
d.Minutes = d.Minutes - 1
I get a DateInterval of
hours = 1
minutes = -1
instead of 59 minutes. Is the DateInterval meant to be used this way?
i believe you can add/sub a interval to a datetime.
You can use any value, 1 hour and - 1 minutes, 59 minute, 60 minutes and -60 seconds…
dateTime will be used with the right order and as the value is the same the result will be the same
I don’t have a DateTime, just the DateInterval because I want to do a countdown. Something like xx hours and yy minutes.
So I make a DateTime of my max countdown value and do the difference with a DateInterval of -1 minute?
If you want to show how much time you have to a final date you can:
dim d as dateInterval = finalDate - datetime.now
where final date is your target datetime
now using the dateInterval props you can show to the user xx hours and yy minutes
Thanks, Antonio, that makes sense. Still thinking that DateInterval should be immutable.