简体   繁体   中英

Convert date to character in particular format In R

I need to map 3-4 different dataframes that have different date formats. How can we convert date in format:

YYYY-MM-DD

to character in the format:

MMM-YY

Create a date object from the string (skip this if your column is already in the Date format):

original_date <- as.Date("2017-07-19", "%Y-%m-%d")

Then format the original date to the new format:

format(original_date, "%b-%y")   
# "Jul-17"

The %b indicates the 3-letter abbreviation of the month and %y is the year without the century. You can find more of these codes and their meaning here: http://strftime.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM