updated using strptime() instead of as.Date() for getting the right granularity