Home > Enterprise >  date variable ASTDT in YYYY-MM-DD format want to convert this into DDMMMYYYY format
date variable ASTDT in YYYY-MM-DD format want to convert this into DDMMMYYYY format

Time:01-21

I have a data frame x with date variable ASTDT in YYYY-MM-DD format. i want to convert this into DDMMMYYYY format. please help me how to select the ASTDT from the data frame and change the format? please note that the ASTDT currently is in DATE format not in character or numeric .

x<-as.Date (x$astdt, format="%d%m%Y")

used the above peace of code but it is not working.

when used str(x) got the below attribute information which shows ASTDT as Date format.

 $ ASTDT      : Date, format: "2003-05-01" "2003-05-13" "2003-08-19" "2004-01-06" ...

CodePudding user response:

You may use the format() function here:

dates <- as.Date(c("2003-05-01", "2003-05-13", "2003-08-19", "2004-01-06"))
output <- format(dates, "%d%b%Y")
output

[1] "01May2003" "13May2003" "19Aug2003" "06Jan2004"

CodePudding user response:

To could use:

x = "2022-05-01"

format(as.Date(x), "%d%b%Y")

Output:

[1] "01May2022"
  •  Tags:  
  • Related