Datetime stored incorrectly in postgresql
See original GitHub issueIssue type:
[x ] bug report
Database system/driver:
[ x] postgres
TypeORM version:
[ ] 0.2.6
(or put your version here)
Steps to reproduce or a small repository showing the problem:
The entity and test call below result in a timestamp in server time(rather than UTC) and without timezone information. This behavior exists as of pull request #1717 as far as I can tell.
@entity() export class DateTest {
@PrimaryGeneratedColumn(“uuid”) public id?: string;
@Column() public date?: Date; }
testRepository.save({date: new Date()});
A potentially dangerous result of this bug is that two different servers in different timezones, but accessing the same database, could read the same entry and construct different timestamps(not just differences in timezone).
The comment here by @chriskalmar is not the actual behavior for postgres. As shown in the example above, new Date() is not stored as UTC.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Why is your server in different timezones? You shall use UTC in any server you have to avoid issues. Try to set
process.env.TZ = "UTC";
in your appI had the same problem (also postgres) and I fixed it with the following attribute for all date columns:
Have a look at these supported column types by TypeORM: http://typeorm.io/#/entities/column-types-for-postgres
Update:
timestamptz
is just an abbreviation of thetimestamp with time zone
mentioned above.