# Android QuestionDay and night times

#### harinder

##### Active Member
Hello..
I wanted to calculate day and night components flying from place A to B, given:
Lat/long of A and B.
Sunrise/sunset times at A and B.
Start time A.
End time B.
Duration = End time - start time
So it could be a duration of 7 hours and start time at A at night 2300(Sunset at A 1830) and end at B at 0600(Sunrise at B 0530). So total night time 06:30 and day time 00:30.
Other combinations like day-night, day-day, night-night also factored in.
I used the Astro lib for sunrise/sunset for A and B.
Can someone guide me on this? Thanks

#### Erel

##### B4X founder
Staff member
You can use DateUtils.PeriodBetween to find the duration between two time points.

#### emexes

##### Expert
How accurate does it need to be? My first thought was that you could rough it out by ignoring latitude and assuming constant travel rate longitudinally and timezonally, but that will present difficulties north of the Arctic Circle (and south of the Antarctic Circle) where sometimes there is no daily sunrise and sunset. I feel like flights that pass through those circles might trip up the ignore-latitude shortcut, but when I had a look at www.flightradar.com there were not many planes venturing that far into the wilderness.

#### harinder

##### Active Member
Emexes,

It doesen't have to be very accurate. Latitude change can be avoided and as you rightly pointed out, applicable to lower and mid latitutes only, due inaccurate dlat and dlong measuring capabilities. Thanks.

Erel
As UI has only one date entry,ie date of departure, then it can so happen that End time goes into next day. Therefore, I prefer using ticks for times and in such a case, use dateutils.addperiod to add one day to End time.
I actually found working out day and night time calculations a little complicated for me, so asking here..
Rgds..

Last edited:

#### Erel

##### B4X founder
Staff member
You always use ticks to represent time points.
I actually found working out day and night time calculations a little complicated for me, so asking here..
Worth watching the date and time video tutorial: https://www.b4x.com/etp.html

As UI has only one date entry,ie date of departure, then it can so happen that End time goes into next day
There is no problem with using PeriodBetween. However if you are only interested in showing the hours difference (not days) then subtracting the end time with the start time will also work.

Replies
2
Views
97
Replies
1
Views
368
Android Question Material.DayNight
Replies
1
Views
158
Android Question day and night duration
Replies
3
Views
868
B4A Library DayNightSwitch
Replies
1
Views
2K