What is the best way to insert time into the database taking into account timezones

Hi All,

I am currently using this package ‘joshowens:timezone-picker’ which helps me to auto detect a users timezone and the ability to change it if needed. My users also have a calendar where they need to insert and event into the database with start and end time and I am using the bootstrap datepicker ‘tsega:bootstrap3-datetimepicker’ but I am having trouble saving the correct time in the database taking into account the users timezone. has anyone done this before? How did you solve it?

Any ideas will be appreciated. Thanks

Save everything in UTC. Convert to users time zone when displaying.

1 Like

@tmikoss Yes that makes sense, but my problem is that the user chooses a date lets say 9th of January at midnight, they mean that in their own time lets say that is Denver mountain time. I need to convert that to UTC from the date picker because to the user it is midnight of the 9th but really it is like 6am UTC time. it is calculating the time offset and adding it to the time that I am having trouble with using a datepicker

moment(someTime).toISOString() ?

@shock Found it, there is a timezone bug in the bootstrap datepicker. It assumes the date you pick in UTC and automatically converts that time to your current timezone and saves that. I am not sure if I am even explaining that right