The two fields above represent a date range. In the first one I’m taking a date (the “game scheduled” value is a date) and subtracting 1 minute. Then in the second field I’m taking that same date and adding 2 minutes. Both of these have to be formatted a certain way so I can use them in my API call.
The issue I’m having is that everything works well up until it gets to the “formatted as” part, then the date completely changes. Here are screenshots from the debugger showing you how the date appears at every step:
Now, supposedly my original date’s timezone is UTC, so that’s what I used in the “formatted as” settings. But regardless of timezone, both the “-1 minute” and the “+2 minutes” fields show the same date after the formatting is added, which makes no sense.
Firstly, a date is a date - there are no timezones involved, it’s just a timestamp.
When you ‘format’ a date, you take that timestamp, and turn into a ‘text’, written as whatever date/time that timestamp represents in the given timezone.
The debugger always displays all dates in the timezone of your own device - which is probably why you’re seeing different dates/time than the ones you’re expecting to see - the actual date (timestamp) is displayed as represented by your device timezone, but the ‘text’ (the result of formatting that date in UTC) displays that same Date (timestamps) in whatever date/time that represents in UTC.
note: Dates/timezones are probably one of the most complicated things to deal with in all of web-development - even to the point that most people don’t actually realise that they’re one of the most complicated things in web development, and simply overlook, or ignore the complexity (I’ve learnt this the hard way).
My general rule now is, unless there’s a very particular reason to use specific timezones when defining and/or displaying dates, all dates should always be defined and displayed in UTC - although, in Bubble there’s no simple native way to specific a timezone when defining a data - aside from when using the Date/Time picker.
Thanks for the explanation, makes sense. I can understand why the date displayed at first (in my own timezone) would be different than the one displayed after the formatting (which would be in UTC, the timezone I set in the custom formatting settings).
But even if the day and hour changes, shouldn’t the minute be the same regardless of timezone?
And in this example I am working with 2 dates (the “date -1 minutes” and the “date +2 minutes”) yet the date I get after the formatting seems to be the same? I just can’t wrap my head around it.
Ah… I see, you’re using a custom date time format…
m = Month
M = minutes
so hh:mm:ss = Hour:Month:Seconds or 11:08:00
August is the 8th month, so as you’re using the Month where the minutes should be, the minutes (or what you think is minutes) is displaying as 08 (mm) instead of the actual minutes (MM)