Skip to content

Cannot store/retrieve UTC dates in sqlite #568

@apoco

Description

@apoco

Version: 2.1.19

When retrieving a Date previously stored in an SQLite database, the date comes back with an offset tacked on, presumably based on the local timezone:

var now = new Date();
things.create({ id: 1, someDate: new Date() });

things.get(1, function(err, thing) {
  var diff = now.getTime() - thing.someDate.getTime();
  // expected: 0, actual: 25200000 (7 hours)
});

I saw in the docs that some of the database engines accept a timestamp option, but SQlite is not one of those engines. Indeed, adding a ?timezone=Z did not remedy the situation.

Is there a way to treat dates as UTC using SQLite? Better yet, is there any way to treat all dates as UTC (as all dates should always be) for all database engines? I realize that as a workaround I can use string dates or make the column numeric and store just the timestamp, but it would be super convenient to just use Date objects and not worry about it. I would expect the same Date I stored would be the same Date coming back, not a new Date with an offset applied.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions