Extracting date from datetime

Is there some reason you can’t do the hours/minutes/seconds change on Searches ? You can do it on Current Date / Time however if you then want to do some calculations on a stored date, you can’t. ?

1 Like

You mean part of a search constraint? That’s a complex thing to do dB wise to be scalable.

Hello, I’m using this approach but running into issues when a user moves time zones. Would very much appreciate any suggestions!

Example:

My app allows users to track the food they eat. When a user logs a food, the app creates an event that has datetime of the current date/time: change minutes to 0: change seconds to 0: change hours to 0.

The app shows all the foods they’ve eaten on a particular day by doing a search for events with datetime of the day in question, with hours, minutes, and seconds all changed to 0.

The problem is that when a user moves time zones. If a user logs a bunch of foods in New York on June 1, 2017, for example, those events will have a datetime of Jun 1, 2017, 12:00 AM, relative to local time (UTC -5). If they go to Los Angeles which is 3 times zones away (UTC -8), the app will display all events that have datetime of Jun 1, 2017, 12:00 AM (UTC -8). However, in UTC -8 time zone, all the events that were logged in New York have datetime of May 31, 2017, 9:00 PM, so the app won’t display them.

What is the best solution to this problem?

I’ve thought about just extracting the date into text, so it would be 06/01/2017, but this feels very sloppy.

Alternatively, I’ve also considered having the app display a date range (from Jun 1, 2017 12:00 AM to Jun 1, 2017, 11:59 PM) and changing the hours of each event’s date/time to 12 instead of 0, so the datetime of an event would be Jun 1, 2017, 12:00 PM (instead of AM). This would work when the user is only traveling across a few time zones (such as across the US), but wouldn’t work when the user is traveling from US to Asia, for example.

Any thoughts on how to accomplish this?

1 Like

We face the same issue… changing hours to 0, minutes to 0 and seconds to 0 isnt helpful since that changes it for the timezone of the user. There needs to a more elegant solution. Something like :remove time which will set hours to 0, minutes to 0, seconds to 0, all in the reference of universal timezone could be helpful

1 Like

Gents. Time is time.

I was faced with a similar situation and there are two solutions I found.

  1. store the date in YYYYMMDD as a text field this way you can force the record to shown under that date and in this formate it will be easily sorted .
  2. you can manually show a time and date in a particular time zone.

So my suggestion is this. Have a fields on the user level to store the timzone. And if the user changes a time zone then have a pop-up say some thing like “you have moved in to a new time zone. Would you like to update your time zone”. Upon choosing yes the users time zone changes and all the data is updated

The way bubble implements timezones is correct. It’s only a matter of handling it correctly.

2 Likes

I think you’re talking about displaying a stored time. I am referring to storing a time.
If you have a 2-sided platform where supply and demand can be in any country across the globe, you aren’t dealing with something like a user moving timezone but tasks more complex than that. Bubble does implement timezones in a correct way, no one is denying that.

My point is that there were a easier way to capture a date only by taking a date-time and setting all time related attributes (hours, minutes, seconds) to 0 in one common timezone e.g. universal time, it would help a lot of people building cross-border apps. This would entail something like: date = input datetimepicker’s value :convert timezone to utc:set hours to 0:set minutes to 0:set seconds to 0.

As of today, setting (hours, minutes, seconds) to 0 sets it the timezone of the browser in which that action took place.

Sorry I missed that bit

As far as my information goes bubble does store time in UTC on is servers. It’s when the data is displayed or called upon it’s rendered in your time zone.

For example if I was to recieve an API call to a bubble endpoint and record the date and time as a text (to stop the auto conversion) then it would show me UTC

I could be wrong though maybe @emmanuel can validate this?

I hope I got the point your trying to make. Let me know

2 Likes

Yes that’s how we do it

So is there then a way to display a date in the timezone it was saved in instead of displaying the server stored UTC as the user’s local timezone?

My users enter a lot of dates, but a user in a different time zone should not see a converted date and time because that can really mess up things.

For example: a delivery date local time would be september 15 but a user in a different timezone could see that as september 14. It is the local time and date that matters in this case.

But creating a text field causes issues with date sort. I can store the text field as YYMMDD but I don’t want to display it as such so I would have to create conditions to display 09 as September.

@gaurav @sridharan.s did you solve an issue like this?

Yes @vincent56, there’s a straightforward way to do this. @kramwe created a public block on Blockspring to enable this for anyone in the community and that’s what I’d recommend you use - Details here.

@kramwe and I use the same code on a different block for our production application and it works well. Took us a while to get it set-up and working the first time, but now that the blocks are coded it should be straightforward for everyone else.

Best,
Scott

1 Like

How could I have missed that topic? I have been going in circles through every topic I could find about this, but never saw this. Awesome, thanks!
Will take a closer look later.

1 Like

Creating a field (text) to save the date SOLVED MY PROBLEM. Ok, i know there’s other way to retrieve the date/time data, but nothing worked out for me here.

Thanks Luke, for make me look at the problem this way.