How to set Vercel's server timezone?
Answered
New Guinea Freshwater Crocodile posted this in #help-forum
New Guinea Freshwater CrocodileOP
Hi there,
I'm hosting a Next site on Vercel and I want my server-side actions all to use the America/New_York time zone for everything, I know it's not the best practice but I don't want to deal with different time zones in my database that already got its time zone set to America/New_York, there much be a way to set the server time zone?!
I'm hosting a Next site on Vercel and I want my server-side actions all to use the America/New_York time zone for everything, I know it's not the best practice but I don't want to deal with different time zones in my database that already got its time zone set to America/New_York, there much be a way to set the server time zone?!
Answered by Rafael Almeida
you can try just doing
process.env.TZ = 'America/New_York' at the start of your code but you need to remember to add it to every single entrypoint, which in a Next.js app is a lot of places21 Replies
New Guinea Freshwater CrocodileOP
help me please 😦
@New Guinea Freshwater Crocodile Hi there,
I'm hosting a Next site on Vercel and I want my server-side actions all to use the America/New_York time zone for everything, I know it's not the best practice but I don't want to deal with different time zones in my database that already got its time zone set to America/New_York, there much be a way to set the server time zone?!
better way is to change everything in your db to use utc
also
@New Guinea Freshwater Crocodile Hi there,
I'm hosting a Next site on Vercel and I want my server-side actions all to use the America/New_York time zone for everything, I know it's not the best practice but I don't want to deal with different time zones in my database that already got its time zone set to America/New_York, there much be a way to set the server time zone?!
try to set a environment variable
TZ="America/New_York"
TZ="America/New_York"
@Ray try to set a environment variable
TZ="America/New_York"
New Guinea Freshwater CrocodileOP
If only it was so easy 😦 "The name of your Environment Variable is reserved. Please choose another name. Learn More"
@!=tgt also
New Guinea Freshwater CrocodileOP
I disagree with that statement because I don't want the extra server process time dealing with all that utc timestamps, also it's Next focus it's on Next.js deployment on VERCEL
what is your db?
@Rafael Almeida what is your db?
New Guinea Freshwater CrocodileOP
it's a Postgres DB running on a local server
for postgres you can create your columns with the
timestamptz type and not worry about timezones. the time stored in the db is in UTC so the timezone of the db wouldn't matterI have set it on lambda and it works
@Rafael Almeida <https://www.postgresql.org/docs/current/datatype-datetime.html>
New Guinea Freshwater CrocodileOP
can't change the structure of the DB, they already have 1000s of entries, and they don't want me to touch it 😦
@Ray https://stackoverflow.com/a/64750535
New Guinea Freshwater CrocodileOP
Vercel doesn't let me save the Environment Variable 😦
you can try just doing
process.env.TZ = 'America/New_York' at the start of your code but you need to remember to add it to every single entrypoint, which in a Next.js app is a lot of placesAnswer
my recommendation still stands to try to handle the timezones instead of changing the timezone of the server itself
if all the timestamps in your database are in UTC all you need to do is to convert it before setting it, using a library like luxon (https://github.com/moment/luxon) makes it easier
New Guinea Freshwater CrocodileOP
Thanks all, will try with process.env.TZ and if that not work I just gonna go the utc route