Is there a way to use the format function on a date object, specifically an object of class POSIXlt, POSIXct, or Date, wi
You can do this with a simple change to your strftime format string. However, it depends on your platform (Unix or Windows).
Insert a minus sign (-) before each term you'd like to remove leading zeros from:
format(as.Date("2020-06-02"), "%Y, %-m, %-d")
[1] "2020, 6, 2"
Insert a pound sign (#) before each desired term:
format(as.Date("2020-06-02"), "%Y, %#m, %#d")
[1] "2020, 6, 2"