## [1] "2021-01-01" "2021-02-01" "2021-03-01" "2021-04-01" "2021-05-01"
## [6] "2021-06-01" "2021-07-01" "2021-08-01" "2021-09-01" "2021-10-01"
## [11] "2021-11-01" "2021-12-01" "2022-01-01"
## PeriodIndex(['2021-01-01', '2021-02-01', '2021-03-01', '2021-04-01',
## '2021-05-01', '2021-06-01', '2021-07-01', '2021-08-01',
## '2021-09-01', '2021-10-01', '2021-11-01', '2021-12-01',
## '2022-01-01'],
## dtype='period[D]')
## PeriodIndex(['2021-01-31', '2021-02-28', '2021-03-31', '2021-04-30',
## '2021-05-31', '2021-06-30', '2021-07-31', '2021-08-31',
## '2021-09-30', '2021-10-31', '2021-11-30', '2021-12-31',
## '2022-01-31'],
## dtype='period[D]')
library(DBI)
library(RPostgres)
library(jsonlite)
# Database connection
config <- jsonlite::read_json('C:/Users/brent/Documents/VS_Code/postgres/postgres/config.json')
con <- DBI::dbConnect(
RPostgres::Postgres(),
host = 'localhost',
port = '5432',
dbname = 'stock_master_test',
user = 'postgres',
password = config$pg_password
)
first_of_month |
---|
2021-01-01 |
2021-02-01 |
2021-03-01 |
2021-04-01 |
2021-05-01 |
2021-06-01 |
2021-07-01 |
2021-08-01 |
2021-09-01 |
2021-10-01 |
with fom as (
select * from generate_series(timestamp '2021-01-01', '2022-01-01', '1 month') as first_of_month
)
select first_of_month - interval '1 day' as end_of_month from fom;
end_of_month |
---|
2020-12-31 |
2021-01-31 |
2021-02-28 |
2021-03-31 |
2021-04-30 |
2021-05-31 |
2021-06-30 |
2021-07-31 |
2021-08-31 |
2021-09-30 |