If you want to use C#, you can look at either the built-in Smart Lights APP or my Advanced Smart Lights code. The built in code uses a luminance sensor to trigger when the motion detection triggers lights to come on. My code modifies this to use the jkUtils APP to determine day/night. In my code, the current time is compared to the sunrise/sunset values set by jkUtils and only allows lights to come on at when it's dark. This should give you one way to only allow your code to turn lights on between given times.
Alternately, you could probably just use a CRON statement and simply use the isscheduling command on it.