Created
November 7, 2016 00:04
-
-
Save hostelix/f57f7719b022ed68d9260ac7f96c8fad to your computer and use it in GitHub Desktop.
Consulta sql para obtener todas las semanas del año con la fecha de inicio y fin de cada una
This file contains hidden or 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
| select | |
| to_char(extract(week from (f1 + (i || ' weeks')::interval)),'09')::integer as semana, | |
| (f1 + (i || ' weeks')::interval)::date as fecha_inicio_semana, | |
| (f2 + (i || ' weeks')::interval)::date as fecha_fin_semana | |
| from ( | |
| select f1, f1 + 6 as f2 from ( | |
| select (current_date -(extract(week from current_date) - 1 || 'weeks')::interval)::date - (extract(dow from current_date)::integer - 1) as f1) as foo1 | |
| ) as foo2, generate_series(0, 52) as i | |
| where extract(year from (f1 + (i || ' weeks')::interval)) = extract(year from current_date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment