Time not showing accurately from hosted server
hi, I was wondering how does Time_zone work in a hosted django project in railway app, because when I use the project the time is working accurately , however the same project in railway server gives a different time.
22 Replies
Project ID:
N/A
i think my projet id is arrivaapp03-production.up.railway.app
railway servers are in UTC unless you override this
oh, iv made mine in django to TIME_ZONE = 'Indian/Maldives'
how ever the time is off, when i use it locally the time is working ok
django time won't do a whole lot if the system time and database times are different
especially things like
TimeField
s, those are near impossible to work with across multiple time zones unless you do a bunch of manual calculation and offsets
might just be me struggling with the concepts, but i had to do a lot of work to get stuff that worked fine on local to work in a production setting because of how django handles datetimesoh, so what is the recommended way to handle time zones in a production server
depends on how you create, store, and then retrieve them
i mean, do i need to set the production servers' <time> manually in order for it to sync
not sure, if you create, store, and parse everything as a timezone aware datetime object it should work
ok, this is my database time, in my railway postgres app:
railway=# select now();
-------------------------------
2023-02-13 06:04:11.908534+00
yeah that's UTC
its actually : 023-02-13 11:04:11
in my localtime
and that's your local TZ
so it might be my db is not configured to my correct timezone right
PostgreSQL Documentation
SET
SET SET — change a run-time parameter Synopsis SET [ SESSION | LOCAL ] configuration_parameter { TO | = } …
yeah
but be careful this may have unintended side effects
oh,,
by looking in the doc, it seems i need to change the time zone in postgres to:
SET timezone TO 'MVT';
Hi locally i can access my postgresql.conf file to update my timezone, where can i access the file in railway app's postgres service, or is there a way i can overide the default values
because if i use SET the docs says:
If SET (or equivalently SET SESSION) is issued within a transaction that is later aborted,
and Once the surrounding transaction is committed, the effects will persist until the end of the session,
Best practice is to set to UTC
do the conversion in your app
thanks, for the tip, but right now i'm looking for a way to update my railway's db to a specific timezone,
that persists
not just for a specific session
because the app is already deployed to production with bunch of models that rely on date and time
Best practice would be to have the databases in utc and have all your projects that draw from it convert to your time zone
Not sure how to change the timezone, that would have to happen when your app enters the data to your database
ok thanks
one quick question, so everything I enter into the db should be in UTC time zone , so where ever and when ever i retrieve them I have to convert it to a my specific time zone right?
one more, is there a way which I can override the railway apps db's server, from UTC to another timezone?
No not at the moment.