How to Convert Today's Midnight in User's Timezone to a UTC Timestamp?

Hey!

I'm working on converting today's date at midnight (00:00:00) into a UTC timestamp, based on the user's timezone. Here's the approach I'm using:

  1. I format the now variable as Y-m-d to get today's date.

  2. I concatenate this date with 00:00:00 to represent the start of the day.

  3. Then, I use the "to_timestamp" function to convert the concatenation into a timestamp, specifying the user's timezone.

This gives me the correct UTC timestamp for when that specific day started in the user's timezone.

Is this a common or recommended approach?

How would others handle this scenario?

I want to make sure Im not over complicating things here

Thanks!

6 replies