I am using knex.js with a postgresql database.
I am looking into replacing moment.js with date-fns in my codebase and I am running into a really odd situation with the formatting of queries.
We are using whereBetween
with two dates. To test the transition from moment to date-fns (that use regular JS Date) I am building a query where the lower bound is a Date and the upper bound is a moment object.
When I try to toString()
it I get two different formats:
select * from "table" where column between '2017-10-23 02:00:00.000' and '2017-10-24 01:59:59.999'
The first one is what I would consider wrong since it is in my timezone as well as not being an ISO string. This one is generated from the date. The other one is generated from a moment object which toString()
would return Mon Oct 23 2017 23:59:59 GMT+0000
but it seems like it is using the toISOString()
that returns the right format: 2017-10-23T23:59:59.999Z
I can’t find the information on how the transformation is carried out and why this isssue arises. Has anyone dealt with this issue ?