A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRExtract Date and Time Parts from a Datetime Value

Introduction

  • Lab results and vitals often carry full datetime stamps β€” we need the date portion for merging with other datasets and the time portion for ordering records within a day.
  • SAS stores datetimes as seconds since midnight on 01JAN1960; extracting the date and time parts requires dedicated functions.
  • R stores datetimes as POSIXct objects (seconds since 1970-01-01 UTC); extracting parts uses lubridate helpers or base formatting functions.
  • This lesson extracts date and time components from a small set of lab datetime values and shows how to get hours, minutes, and seconds individually.
  • Understanding the underlying storage model is important β€” it explains why we cannot simply assign a datetime to a date variable without an explicit extraction step.

Extract Date and Time Parts from a Datetime Value