Created
May 18, 2018 09:10
-
-
Save viniroger/bc397166621d598fc3432f5f0a82ba38 to your computer and use it in GitHub Desktop.
Função para escrever número da semana entrando com data formato YYYY-mm-dd (conferir em http://whatweekisit.org/calendar-2018.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date_ini = '2018-05-10' | |
get_week_numbers = function(date_ini){ | |
# Week number of first day from next month (1st week) | |
week_ini = as.integer(format(as.Date(date_ini), '%W')) | |
# Week number of first day from next-next month (4th or 5th week) minus 1 (+2 pra completar 6 semanas) | |
date_end_temp = as.character(as.Date(date_ini) + 31) | |
date_end = paste(strsplit(date_end_temp, '-')[[1]][1], strsplit(date_end_temp, '-')[[1]][2], '01', sep = '-') | |
week_end = as.integer(format(as.Date(date_end), '%W')) - 1 + 2 | |
# Return array with year and week numbers | |
year = format(as.Date(date_ini), '%Y') | |
c(as.numeric(year), as.numeric(week_ini), as.numeric(week_end)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment