Database/Lucid DateTime Problems while saving/reading

I have problems when using DateTime values with SQLITE

In my migration i write following:

      table.timestamp('created_at').defaultTo(this.fn.now())

All runs fine, but “created_at” will stored in utc. How must i handle this, when i return such values via:

      const records = await Database
         .table('an_pk')
         .select('*')

or

      let records = await AnPk
        .all()

The created_at is returned in UTC but i must have this in timezone “Europe/Berlin”.

Or is there a way to stored the values in local format?

Bye, René

1 Like

That is how Date.now() function behaves.

AdonisJs offers at least 2 clean solutions to your problem:

  1. Using setters to save data in the format you want.
  2. Using getters in case you care how the data is displayed to the end user.

If you opt for the second approach, you may use my solution posted here.

If you prefer the first option, it is just as easy to implement as shown on the documentation.

If you prefer the first option, I can provide you a solution (even it is better you give it a try yourself first)

Thanks a lot!