I am attempting to create a web (react/sequelize) front end to an existing database.
When I perform a select from the database the returns results in sequelize have the date as off by 1 (-1).
Here is the SQL and code used to get the data:
let sql1 = 'SELECT count(RECEIVED_DATE) as CallCount, CAST(RECEIVED_DATE AS DATE) as CallDate FROM TowCalls WHERE OFFICE_ID = ? AND (RECEIVED_DATE BETWEEN dateadd(day,?, GETDATE()) AND GETDATE()) group by CAST(RECEIVED_DATE AS DATE) ORDER BY CAST(RECEIVED_DATE AS DATE)';
models.sequelize.query(sql1, { replacements: [id, -7], type: models.sequelize.QueryTypes.SELECT })
.then(function(summary) {
When I output summary to the console I get:
[
{ CallCount: 22, CallDate: '2020-12-16' },
{ CallCount: 36, CallDate: '2020-12-17' },
{ CallCount: 20, CallDate: '2020-12-18' },
{ CallCount: 12, CallDate: '2020-12-19' },
{ CallCount: 28, CallDate: '2020-12-20' },
{ CallCount: 13, CallDate: '2020-12-21' },
{ CallCount: 1, CallDate: '2020-12-22' }
]
When I use the same query in SQL Server itself I get the same counts, but all the dates are +1.
Although I never specifically set it, I believe the dates are in SQL in EST timezone.
All the users of the database are in the same timezone so I never had to worry about tracking any changes.