I am trying to compare two dates in C#. One is a sunset date and one is the current date. I am trying to determine whether it's after or before sunset. I have two dates like that:
- 2021-12-02 16:19 (Current Date)
- 05:55:50 PM (Sunset Date)
I have been trying to compare them this way:
var currentTime = DateTime.ParseExact(Weather.location.localtime, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture).TimeOfDay;
var sunsetTime = DateTime.ParseExact(SunriseSunset.results.sunset, "hh:mm:ss tt", CultureInfo.InvariantCulture).TimeOfDay;
bool sunStillUp = currentTime < sunsetTime;
I know that the error means that the given dates are in incorrect format, however I cannot see how..
Weather.location.localtime is this (getting data from an api):
And SunriseSunset.results.sunset is this (getting data from an api):