Sunrise-sunset times stack?

I’m looking for a stack that automatically provides daily sunrise and sunset times for a given location, as set by longitude and latitude. Ideally, the total amount of daylight in hours and minutes for that location and date would also be provided. The icing on the cake would also include civil twilight times for that location and date. Conceptually, presentation of the stack’s information might look like this:


Sunrise Today: 7:28 am
Sunset Today: 4:23 pm

Daylight
7:28 am – 4:23 pm
8 hours, 55 minutes

Civil Twilight
6:53 am - 7:28 am
4:23 pm - 4:58 pm


All this is for a weather page for an airport’s website; this information is important for pilots as a part of their flight planning, especially in winter months when daylight hours are limited. The source I used for the above sample times is: Sunrise and sunset times in Seattle

Any suggestions would be gratefully accepted!

Thanks.

I love this idea (and your favicon).

Not sure of a stack per se, but what about pulling a NOAA RSS feed that publishes this info?

I found this NOAA site for a town in TN that has the sunrise and sunset data in RSS format. If this works, then there are several stacks that can help.

After a few minutes on the NOAA site, it seems that the National Weather Service provides weather forecast data relevant to towns and cities. But airports like the one I’m working with are nowhere near a town. (I was surprised to learn that sunrise-sunset times change even over relatively short distances.) On the NOAA site, I found no means to narrow the geographic area of a forecast further than a town.

The most accurate way to provide specific location information is by latitude and longitude, though for locating an airport, an ICAO airport code, ie., KSEA (KSEA = Seattle-Tacoma airport), would also meet that need.

But I’ll take anything I can get, so yes, please tell me about stacks with RSS function that might work.

Thanks for that!

I dabble in Amateur Radio and sunrise and sunset times are important as it’s the best times for pushing a radio signal to extreme distances. (Frequency dependant).

I always like GEOChron clocks and you may find one on the internet to fit your needs. Take a look at this one for example: http://www.fourmilab.ch/cgi-bin/Earth

Here is one for use on a Raspberry PI. It’s free and makes a great project to hangs a large screen on the wall with just this app running. http://kd2iff.com/node/20. Another reasons for pointing you at this page is the small side bar plugin that many Amateur Radio enthusiasts use on their web pages called “Solar Terrestrial Data”. I’m not sure it gives sunrise or sunset times at first look but if you go to the owner website here http://www.hamqsl.com/solar.html, then one of the options is to give it a GeoChron style of view. Again it’s free to use with just a tiny bit of html code.

There are others about that may give you the ability to zoom in to your location and give a more accurate picture.

With a “time” stack, it would be possible to create the catalina/big sur desktop effects :+1:

I think @willwood has a lot of experiences with weather-related Stacks or programming in general. Tagging him so that he can chime in here.

1 Like

I did sometime ago a quick and dirty job for a drone enthusiast page, nothing fancy, not even a stack:

Screenshot 2020-11-25 at 11.54.11

Check it out here:
http://heiko.codes/demos/sunsetsunrise

If’s a very simple PHP Script using the data from the Sunset & Sunrise API, however, calculating the times is pure Math, so any Javascript Library would to the job.

If this is any help for you, you can download a simple RW file with the code and a general purpose PHP Stack (any PHP Stack will do):
http://heiko.codes/downlads/sunsetsunrise.zip

Just update the variables to your need:

1 Like

Heiko, what you’ve provided is exactly what I was looking for. Changing $lat and $lng and trimming a few unneeded lines from the php produced the desired result, albeit in UTC+1. As a novice I took a look at tutorials at w3schools for info about creating a simple JS script for the time conversion, but it was over my head. I have no idea how incorporate JS into PHP–or even if that’s how it would be done.

I’m in UTC-8. Could you point me to a way to add a calculation to my timezone?

Many thanks for your help, Heiko!

John

Wow…there’s some serious data available behind those links. Thanks for the heads-up on them.

1 Like

My bad, the code was using the time zone of the api server.

I have attached the project file with and updated code snipped that uses the time zone of the server who hosts the files, hope this helps.
(If not, we have to convert the time zone)

http://heiko.codes/downloads/sunsetandsunrise_newdate.zip

After applying your updated code with my lat/long, I find that time and date results remain in UTC1 (not UTC-8/Pacific Standard Time where I’m located), so it appears that converting the time zone may be the best solution.

(The formatting of your initial demo PHP file is exactly what I’ve been looking for.)

Sorry to bother you with this; thank you for your assistance!

Happy to help :wink:

Check out this changes, you can configure the formatting now and adjust the timezone for your needs.

http://heiko.codes/downloads/sunsetsunrise_timezone_support.zip

Hello Heiko,

I very much appreciate your time with this project.

Sunrise and sunset times appear to be in error, though daylight hours and the timezone is correct. Here are the steps I’ve taken to sort it out:


  1. Verified latitude and longitude, using Lat Long Data, which matched coordinates to physical location


  1. Verified correct sunrise and sunset times, and hours of daylight for today’s date (11/28/20) and location (Pacific Standard Time/UTC-8), using timeanddate.com
  • sunrise today: 7:37am
  • sunset today: 4:21pm
  • daylight hours: 8 hr 44 min


  1. Configured the PHP you kindly provided to me, setting coordinates and timezone as appropriate

__________________________________________________________________________________

  1. Obtained the following results from the sunrise-sunset API and above PHP:
  • sunrise today: 7:11am
  • sunset today: 4:11pm
  • daylight hours: 8 hr 44 min


It seems that the problem lies with the sunrise-sunset API, as it produces times for sunrise-sunset that are not correct, nor are results for civil twilight. Further adding to my suspicion is that minutes for all results (except Day Length) are equally eleven minutes past the hour. In the scope of things, and given the time that would be needed to root out the problem, perhaps it would be best to put this to rest.

I’m grateful for your help with all this; thanks, mate.

How about using this code snippet found here -> https://www.w3schools.com/php/phptryit.asp?filename=tryphp_func_date_sunrise

1 Like

I plugged in and tweaked the snipped you provided, and came up with similar inaccurate results for the local area.

A few, somewhat clunky solutions come to mind:

  • embed sunrise/sunset data from timeanddate.com or other reliable source
  • embed tables with data for my area from NOAA

It’s not what I’d hoped for, but it’ll work.

Thanks for your suggestion, John.

It may be worth documenting a couple of inaccurate results and then contacting sunrise-sunset.org to let let them know. I’m sure they’d want to know that their times were wrong. They can probably fix their service.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.