https://github.com/curzon01/mysql_sunriseset
MySQL/MariaDB SunRiseSet Calculation
https://github.com/curzon01/mysql_sunriseset
algorithm algorithms-implemented mariadb mysql sunrise sunset
Last synced: 7 months ago
JSON representation
MySQL/MariaDB SunRiseSet Calculation
- Host: GitHub
- URL: https://github.com/curzon01/mysql_sunriseset
- Owner: curzon01
- License: gpl-3.0
- Created: 2018-11-06T08:13:55.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-18T07:57:44.000Z (over 2 years ago)
- Last Synced: 2025-01-06T02:42:53.992Z (9 months ago)
- Topics: algorithm, algorithms-implemented, mariadb, mysql, sunrise, sunset
- Size: 17.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MySQL SunRiseSet Calculation
MySQL/MariaDB function to calculate the sunrise/sunset time based on date and latitude/longitude.
This implementation is based by the algorithm found on http://web.archive.org/web/20161202180207/http://williams.best.vwh.net/sunrise_sunset_algorithm.htm
A more powerful variant can be found as a MySQL Loadable Function implementation under [lib_mysqludf_astro](https://github.com/curzon01/lib_mysqludf_astro).
## Installation
Execute the code of SunRiseSet.sql, for example
```
mysql -u -p < SunRiseSet.sql
```## Usage
Call the function with date, your location and which time you want to get back (sunrise, sunset)
### SunRiseSet(date, latitude, longitude, zenith, sunriseset)
The paramater are:
#### date
Date of interest - MySQL date format `yyyy-mm-dd`#### latitude
Location latitude - FLOAT#### longitude
Location longitude - FLOAT
Positive for east and negative for west.#### zenith
Sun's zenith for sunrise/sunset: enum['official','civil','nautical','astronomical'] or FLOAT#### sunriseset
Desired result - enum['sunrise','sunset']### Examples
Replace latitude 0.0000 and longitude 0.0000 with your local settings:
```
-- official sunset/sunrise
SELECT system.SunRiseSet(NOW(), 0.0000, 0.0000, 'official', 'sunset'), system.SunRiseSet(NOW(), 0.0000, 0.0000, 'official', 'sunrise');
SELECT system.SunRiseSet(NOW(), 0.0000, 0.0000, 90+(50/60), 'sunset'), system.SunRiseSet(NOW(), 0.0000, 0.0000, 90.833333333, 'sunrise');
-- civil
SELECT system.SunRiseSet(NOW(), 0.0000, 0.0000, 'civil', 'sunset'), system.SunRiseSet(NOW(), 0.0000, 0.0000, 'civil', 'rise');
SELECT system.SunRiseSet(NOW(), 0.0000, 0.0000, 96, 'sunset'), system.SunRiseSet(NOW(), 0.0000, 0.0000, 96, 'rise');
-- nautical
SELECT system.SunRiseSet(NOW(), 0.0000, 0.0000, 'nautical', 'set'), system.SunRiseSet(NOW(), 0.0000, 0.0000, 'nautical', 'rise');
-- astronomical
SELECT system.SunRiseSet(NOW(), 0.0000, 0.0000, 'astro', 'sunset'), system.SunRiseSet(NOW(), 0.0000, 0.0000, 'astro', 'sunrise');-- self defined sun horizon level
SELECT system.SunRiseSet(NOW(), 0.0000, 0.0000, 86.2, 'sunset'), system.SunRiseSet(NOW(), 0.0000, 0.0000, 86.2, 'sunrise');
```