0

I have a data frame of daily dates from December 2018, until March 2019, and I need to find the "Index of the day" because it is the input of another function to calculate time and sunset.

The "Index of the day" is the number of days compared to the other days of the year. Example.- January 5 (5 of 365); February 1 (32 of 365), etc.

  • so you need day of the year from date ? Possible duplicate https://stackoverflow.com/questions/7958298/how-do-you-convert-posix-date-to-day-of-year-in-r – Ronak Shah Sep 04 '19 at 09:48
  • You can try `days <- as.Date(c("01-01-2010", "01-10-2010"), format = "%d-%m-%Y") format(days, "%j")`. – tmfmnk Sep 04 '19 at 09:52

2 Answers2

0

You can do this as follows:

as.numeric(difftime(Sys.Date(),as.Date(paste0(format(Sys.Date(),"%Y"),'-01-01')),units = "days"))

For today the result is

246

Wietze314
  • 5,942
  • 2
  • 21
  • 40
0

There is a yday function in the lubridate package.

lubridate::yday(ymd('2019-09-04')) #247
Tony Ladson
  • 3,539
  • 1
  • 23
  • 30