Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Dates
Summary

Instruction

As you can guess, there are functions for all possible date formats. For example, you would use the following functions:

  • ymd_hms(), ydm_hms(), dmy_hms() to parse a date time format with its parts: year, month, day, hour, minute, and second.
  • ymd(), dmy() to parse only dates.
  • ymd_h(), mdy_h() to parse only dates and hours.

You may check out all formats at the lubridate's reference page.

We can also extract only the date from the departure_datetime column. To do this, we need the date() function:

trucks$departure_date <- date(trucks$departure_datetime)

The function will drop the hours, minutes, and seconds of the date and it will only return the date.

Exercise

Extract the date from the ships' departure_datetime column into a new column: departure_date.