48

I want to convert "2013-09-16" into unix time.

I found Convert UNIX epoch to Date object in R but I need to do the reverse of that.

Thanks!

Community
  • 1
  • 1
Ignacio
  • 7,646
  • 16
  • 60
  • 113

3 Answers3

85

Quite simple:

as.numeric(as.POSIXct("2013-09-16 2:13:46 EST"))

Henrik
  • 65,555
  • 14
  • 143
  • 159
hot_whisky
  • 1,072
  • 1
  • 9
  • 10
14

Simply cast to numeric:

as.numeric(as.POSIXct("2013-09-06", format="%Y-%m-%d"))
# [1] 1378418400
Tomas
  • 57,621
  • 49
  • 238
  • 373
0

This tipe of time is useful for YahooFinance i'll leave you a code if you want to see 60 days before until today:

  window <- 60
  tempo<-as.character(Sys.time())
  substr(time, 12, 24) <- "00:00:00"
  tempo<-as.POSIXct(tempo)
  end_date <- ceiling(as.numeric(as.POSIXct(tempo)))
  start_date <- ceiling(as.numeric(as.POSIXct(tempo - window*86400)))

This code will give you an interval for download the time that you want.

WAC.