0

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

null
    • alistair_frith
    • yesterday
    • Reported - view

    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?

      • smason
      • 7 hrs ago
      • Reported - view

      Would something like this work?

      I'm hardcoding a value for sunRise, whereas you have a tag, but I'm forcing it to a String type which I then concatenate in the 2nd expression. With a new string built, I pass it into the DurationSinceDateTime() function.

Content aside

print this pagePrint this page
  • 7 hrs agoLast active
  • 2Replies
  • 6Views
  • 3 Following