1
$\begingroup$

Im trying to extract a list of times from a list of Dates from the Sunrise function

Sunrises = 
  Sunrise[Entity["City", {"Lossiemouth", "Moray","UnitedKingdom"}], 
   DateRange[DateObject[{2019, 1, 1}], DateObject[{2019, 12, 31}]]]]

I have used this as a list of pairs and extracted the lastr elements so that the times are displayed using

Last /@ %2

Is it possible to convert this from the given format, to a list. Such that the list only displays the the sunrise time for each day?

For example

Sunrise={0956,0956,0955} and so on.....

Thanks,

Luke

$\endgroup$
  • $\begingroup$ Using your Last approach: DateValue[Last /@ Normal[Sunrises], {"Hour", "Minute"}]. $\endgroup$ – Alx Sep 19 at 14:15
0
$\begingroup$
Sunrises = 
  Sunrise[Entity["City", {"Lossiemouth", "Moray","UnitedKingdom"}], 
   DateRange[DateObject[{2019, 1, 1}], DateObject[{2019, 1,5}]]]

You can use DateString on Sunrises["Values"] :

DateString[#, {"Hour", "Minute"}] & /@ Sunrises["Values"]

{"0356", "0356", "0355", "0355", "0354"}

To get {hour, minute} pairs you can use Part:

Sunrises["Values"][[All, 1, 4 ;;]]

{{3, 56}, {3, 56}, {3, 55}, {3, 55}, {3, 54}}

$\endgroup$
  • $\begingroup$ Thank you very much for your help. $\endgroup$ – Luke4737 Sep 20 at 5:55
  • $\begingroup$ @Luke4737, my pleasure. Thank you for the accept. $\endgroup$ – kglr Sep 20 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.