Date/time arithmetic in Calculations
Apologies if this is a silly question or if I'm repeating something I've already asked (I'm sure I asked something like this a while ago) but what is the best way to do date and time arithmetic in Canary Calculations?
Here's my scenario: I know the hour and minute of sunrise and sunset. I was to add or remove an offset to get the earliest and latest times my solar panels should be expected to be generating. So I want to do something like:
EarliestGeneration = DateTime(sunriseHour, sunriseMinute) + Minutes(45)
LatestGeneration = DataTime(sunsetHour, sunsetMinute) - Minutes(45)
ShouldBeGenerating = Now() > EarliestGeneration AND Now() < LatestGeneration
but of course DateTime(), Minutes() and Now() are not functions in Canary. The only function I've found that might be able to do this is DurationSinceDateTime(). So maybe I have to do something like
ShouldBeGenerating =
DurationSinceDateTime ([sunriseHour]*3600 + [sunriseMinute]*60 + 45*60) > 0 and
DurationSinceDateTime ([sunsetHour]*3600 + [sunsetMinute]*60 - 45*60) < 0
Or is there a better way of doing tis kind of data and time calculation?
2 replies
-
Discovered I also have SunriseSeconds and SunsetSeconds, being the total seconds since the start of the day for Sunrise and Sunset. So that makes the calculation much easier.
However the question still stands: how would I build up a sting hat can be passed to DurationSinceDateTime()? and is DurationSinceDateTime("Today") the best way to get the current time?