3
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

You can use DateString with {"Hour", ":", "Minute"} as the second argument:

DateString[#, {"Hour", ":", "Minute"}] &["Wed 18 Feb 1801 18:00"]

"18:00"

$\endgroup$
  • $\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 at 18:12
0
$\begingroup$

Another possibility is to use TimeObject/DateObject, and then convert to a string if needed:

TimeObject @ DateObject @ "Wed 18 Feb 1801 18:00"
DateString @ %

enter image description here

"18:00"

$\endgroup$
  • $\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 at 18:13

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.