0

Date & time functions in calculations

I'm trying to calculate approximate sunrise/sunset times for each day of the year for a solar generation application. I have them worked out in Excel and need to transfer the calculations to Canary. But I need to get the current day of the year: 1 to 366, and to convert from a number of seconds since midnight to a time. I can't see any functions to do this. Can anyone help?

2 replies

null
    • smason
    • 1 mth ago
    • Reported - view

    Hi ,

    You're best bet is to use the DurationSinceDateTime('year'). This will output the number of milliseconds since the start of the year which you could convert into days. You could do the same and convert the number of seconds since midnight using DurationSinceDateTime('day'), but I'm not sure how you would convert that to an actual time. Maybe through a series of embedded "if" statements???

    • alistair_frith
    • 1 mth ago
    • Reported - view

    Yes, that's what I used in the end, and converted it to days.

    Then I treated that as a rough angle (365 is close enough to 360) and took the sine of it. Finally I adjusted the earliest local sunrise by that sine value to get today's sunrise in seconds since midnight (with some more conversions, offsets and scaling at various points) and the equivalent calculation for today's sunset.

    The results seem good enough for my purposes.

    It's a shame these time constants are not available in the sidebar along with the functions, tags and operators. And also that the description of the Sin() function doesn't state that the supplied angle needs to be in Radians.

Content aside

print this pagePrint this page
  • Status Answered
  • 1 mth agoLast active
  • 2Replies
  • 24Views
  • 2 Following