Case
x=IsDayLight(strDateTime,opt)
DaylightAug5am=IsDayLight("17/08/2017 05:00:00")
If IsDayLight(Now()) Then LightsOff Else LightsOn
Print IsDayLight("12/10/2020 15:30:00",1)
Print IsDayLight(Now(),2)
Function IsDayLight(dt$,opt as integer) As Integer 'opt = 1, return daytime start, 2, return daytime end anything else return bool of daytime now Local Integer mn,st,fn,st0,fn0,dd,mm dd=DatePart("dd",dt$):mm=DatePart("mm",dt$) Do Select Case mm Case 1:st=490:fn=960 Case 2:st=460:fn=1010 Case 3:st=405:fn=1060 Case 4:st=335:fn=1115 Case 5:st=275:fn=1165 Case 6:st=230:fn=1210 Case 7:st=230:fn=1220 Case 8:st=265:fn=1190 Case 9:st=315:fn=1115 Case 10:st=360:fn=1060 Case 11:st=415:fn=990 Case 12:st=470:fn=955 Case 13:st=490:fn=960 End Select If fn0<>0 Then Exit Do fn0=fn:st0=st mm=mm+1 Loop st=st0-(((st0-st)/30)*dd):fn=fn0-(((fn0-fn)/30)*dd) Select Case opt Case 1 IsDayLight=st Case 2 IsDayLight=fn Case Else mn=(DatePart("h",dt$)*60)+DatePart("m",dt$) IsDayLight=(mn>=st) And (mn<fn) End Select End Function
Function Mins2Time(t As Integer) As String Local Integer h h=(t\60) Mins2Time=ZPad$(h,2)+":"+ZPad$(t-(h*60),2)+":00" End Function