I have a case where users enter predictions about questions (e.g. “how likely will we go into a recession”). For every answer, I want to record the date so that I can display them on a chart. To do this, I need the date without the time, so I’m trying to zero out the hours / minutes / seconds and set them to midnight.
However, whenever I try to modify dates (either with Bubble’s built in functions or using date() related things with the javascript toolbox), I run into issues with users in different timezones creating records that have different datetimes.
For example, a user that triggers the workflow on the East Coast of the US will create a record that correctly zeroes out the hours/etc. to be “May 23rd, 12:00am.” But a user on the West Coast will create a record that is “May 23rd, 3:00am”. Clearly the workflow is setting the hours to zero but in their local timezone, so it’s a 3 hour offset to where I am and where I want it to be. I’m fairly certain this is because of how JS handles dates and times but I can’t figure out how to get around this.
For reference, after failing to find any success using out-of-the-box Bubble date/time functions, I tried using the JS Toolbox plugin with the below code to generate and store a date on page load. Then, when my workflow runs it stores this date on the record. I thought creating a string and setting it to the appropriate time zone would fix things, but I still get users who are logged in on the west coast storing dates that are off by 3 hours.
var myDate = new Date();
var pstDate = myDate.toLocaleString("en-US", {
timeZone: "America/New_York", year:'numeric', month:'numeric', day:'numeric'
});
bubble_fn_jsdate(pstDate);