0
votes

I'm using nodejs to develop an application and I have to create a history table where I 'm basically just copying the old records from main table and inserting in history table when main table records get updated or deleted . I have a field created_at of type timestamp without time zone .When I select rows from main table using select query I get created_at=2018-03-15T09:14:06.980Z,which in postgres DB is something like 2018-03-15 09:55:53.382 .This is the object I get after select query:

{
id: '8',
created_at: 2018-03-15T04:25:53.382Z,
user_id: '7',
updated_at: 2018-03-15T06:27:50.762Z }

But when I try to insert the the record the created_at and updated_at fields become values like Thu Mar 15 2018 09:55:53 GMT+0530 (India Standard Time) which creates error Now I'm confused and also can't understand how to convert this format of timestamp Thu Mar 15 2018 09:55:53 GMT+0530 (India Standard Time) to timestamp without timezone

Also this problem doesn't get solved if I convert it to milliseconds!

1

1 Answers

0
votes

converting the fields created_at and updated_at to ISO String using date.toISOString() or using new Date(Date.parse(date)).toJSON() does the magic