In this tutorial, you will learn how to extract year from date in R. You will learn by a couple of examples containing R code along with a description of the code. To know how to extract the year from DateTime may be needed when working with data containing datetime (e.g., 2020-08-24 10:34:00) and you want to do e.g. time series analysis but only want to use year.

As you may already know, R is a versatile statistical programming environment, and there are many ways to extract elements, such as year, from datetime. For example, we can separate year using the format() function. In this post, however, we need to start by converting a vector, or a column in a dataframe (e.g., to a POSIXct class) as well as use the lubridate package. It is, of course, possible to adapt the examples in this post to extract time, and to extract day.