How to Convert Numbers to Dates in R? Last Updated : 28 Dec, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to convert Numbers to Dates in R programming language. Method 1: Convert Integer to Date Using as.Date() & as.character() Functions Here we have to consider an integer and then first we have to convert that integer into a character using as.character() function and then convert that character using as.Date() function and finally convert into date using "%Y%m%d" format Syntax: as.Date(as.character(integer),format = "%Y%m%d") where, an integer is an input number Example: Convert Numbers to date R # declare an integer data=2021112 # display print( as.Date(as.character(data),format = "%Y%m%d")) # declare an integer data1=20201209 # display print( as.Date(as.character(data1),format = "%Y%m%d")) Output: [1] "2021-11-02" [1] "2020-12-09"Method 2 : Convert Integer to Date Using strptime() Function strptime() is used to convert into the date from an integer in the "%Y%m%d" format Syntax: strptime(integer, format = "%Y%m%d") Example: Convert Numbers to date R # declare an integer data=2021112 # display print( strptime(data, format = "%Y%m%d")) # declare an integer data1=20201209 # display print( strptime(data1, format = "%Y%m%d")) Output: [1] "2021-11-02 UTC" [1] "2020-12-09 UTC"Method 3: Convert Integer to Date Using ymd() Function of lubridate Package Here ymd() is used to convert the integer into year, month, and date which is available in lubridate() package Syntax: ymd(integer) Example: Convert Numbers to date R # load the package library("lubridate") # declare an integer data=2021112 # display print(ymd(data)) # declare an integer data1=20201209 # display print(ymd(data1)) Output: [1] "202-11-12" [1] "2020-12-09" Comment More infoAdvertise with us Next Article How to Convert Text to Date in Excel M manojkumarreddymallidi Follow Improve Article Tags : R Language R-DateTime Similar Reads How to Convert Date to Numeric in R? In this article, we will discuss how to convert date to numeric in R Programming Language. Method 1: Using as.numeric() This function is used to convert date into numeric Syntax: as.numeric(date) where the date is the input date. Example: R data = as.POSIXct("1/1/2021 1:05:00 AM", format="%m/%d/%Y % 2 min read How to Convert Text to Date in Excel Have you ever found yourself staring at a column of dates in Excel, only to realize theyâre formatted as text? It's a common problem that can hinder your data analysis and reporting tasks. Fortunately, converting text to date in Excel is straightforward. If you're looking to use the Text to Columns 5 min read How to Convert Text to Date in Excel Have you ever found yourself staring at a column of dates in Excel, only to realize theyâre formatted as text? It's a common problem that can hinder your data analysis and reporting tasks. Fortunately, converting text to date in Excel is straightforward. If you're looking to use the Text to Columns 5 min read How to Convert Text to Date in Excel Have you ever found yourself staring at a column of dates in Excel, only to realize theyâre formatted as text? It's a common problem that can hinder your data analysis and reporting tasks. Fortunately, converting text to date in Excel is straightforward. If you're looking to use the Text to Columns 5 min read How to merge date and time in R? The date and time objects in R programming language can be represented using character strings in R. The date and time objects can be merged together using POSIX format or in the form of datetime objects. The POSIXlt class stores date and time information. Discussed below are various approaches to c 3 min read JavaScript Program to Convert Date to Number This article will explain how to convert a Date into a Number using JavaScript. The JavaScript Date object is used to get dates and times. It helps in formatting the dates. We can use the new keyword to create an object for Date. To convert a Date to a Number, we use the getTime() method. getTime() 2 min read Like