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$
1
  • $\begingroup$ Using your Last approach: DateValue[Last /@ Normal[Sunrises], {"Hour", "Minute"}]. $\endgroup$
    – Alx
    Commented Sep 19, 2019 at 14:15

1 Answer 1

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$
2
  • $\begingroup$ Thank you very much for your help. $\endgroup$
    – isaac5122
    Commented Sep 20, 2019 at 5:55
  • $\begingroup$ @Luke4737, my pleasure. Thank you for the accept. $\endgroup$
    – kglr
    Commented Sep 20, 2019 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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