I have a dataset of dates in the following format - Wed 18 Feb 1801 18:00. I want to extract only 18:00 from these dates i.e, the time component only. How do I go about doing so?
$\begingroup$
$\endgroup$
You can use DateString
with {"Hour", ":", "Minute"}
as the second argument:
DateString[#, {"Hour", ":", "Minute"}] &["Wed 18 Feb 1801 18:00"]
"18:00"
-
$\begingroup$ Thank you for your reply. But I have trouble applying it to a column in the dataset. For example, I tried extracting the year component - DateObject[Data1[All, "SalesDate"] // Normal, "Year"], where SalesDate appears as Wed 18 Feb 1801. I am confused. Please help $\endgroup$ – Priyesh Sharma Feb 25 '19 at 18:12
$\begingroup$
$\endgroup$
Another possibility is to use TimeObject
/DateObject
, and then convert to a string if needed:
TimeObject @ DateObject @ "Wed 18 Feb 1801 18:00"
DateString @ %
"18:00"
-
$\begingroup$ Thank you for your reply. But I have trouble applying it to a column in the dataset. For example, I tried extracting the year component - DateObject[Data1[All, "SalesDate"] // Normal, "Year"], where SalesDate appears as Wed 18 Feb 1801. I am confused. Please help $\endgroup$ – Priyesh Sharma Feb 25 '19 at 18:13