I'm trying to post the date in the request body in postman
date_borrow: 2021-01-01 date_return: 2021-02-01
but the body response produces output
{
"success": true,
"message": "success",
"data": [
{
"date_borrow": "2020-12-31T16:00:00.000Z",
"date_return": "2021-01-31T16:00:00.000Z"
}
]
}
i use node.js express for rest-api
addBorrowingMember(req,res){
let dataBorrowingMember = {
date_borrow : req.body.date_borrow,
date_return : req.body.date_return
}
pool.getConnection(function(err, connection) {
if (err) throw err;
connection.query(
`
INSERT INTO borrowing SET ?;
`
, [dataBorrowingMember],
function (error, results) {
if(error) throw error;
res.send({
success: true,
message: 'success',
});
});
connection.release();
})
},
I want the date format the same as the request body like this date_borrow: 2021-01-01 date_return: 2021-02-01
It seems that you use postgresql as database and postgresql stores date in UTC +00.
To choose a timezone:
SELECT * FROM pg_timezone_names;
And set as below given example:
ALTER DATABASE postgres SET timezone TO 'Europe/Berlin';
Use your DB name in place of postgres in above statement.
Because you did not specify a timezone for express server, so the system defaulted the datetime to UTC … so there is a difference between the time you add ( even from the browser ) to the date saved by the server , it depends on the difference between your timeZone and the server UTC timeZone .