Is there a shorter way to extract a date from a string?

前端 未结 4 2105
轮回少年
轮回少年 2021-01-12 02:14

I wrote code to extract the date from a given string. Given

  > \"Date: 2012-07-29, 12:59AM PDT\"

it extracts

  > \"         


        
4条回答
  •  迷失自我
    2021-01-12 03:03

    Something along the lines of this should work:

    x <- "Date: 2012-07-29, 12:59AM PDT"
    as.Date(substr(x, 7, 16), format="%Y-%m-%d")
    

提交回复
热议问题