Search code examples
rdate-formatting

Formatting "YYYY-MM-DD HH:MM" timestamp to Date


I have a data set with two columns, house prices and the date (and time) of sale, although the time is 00:00 for all of them. The date column has the format of YYYY-MM-DD 00:00.

I want to remove the time from the column so that the column is left with just the date which I can then sort in an order and plot on a graph.


Solution

  • If your date is in the format you specified you can simply use as.Date() like so:

    b = '2018-09-20 12:30'
    
    a = as.Date(b)
    

    Try it out