Database / Dates without time

Good morning ;

How can I make Bubble save only dates in the database… without time ?

Why do you need to do that?

Thank you for your reaction.

I’ll describe the problem, and I apologize if I can’t get the message across because I’m using Google translator.

I’m using a Date/TimePicker which I’ve set to take the date only.

Despite this, Bubble saves the date with the time “14/06/2023 12am”. But this information distorts the calculations because for some users, Bubble records the date “14/06/2023 11pm” because of users’ time zones.

What does the data relate to?

As a matter of fact…
I want to calculate the difference between today’s date and the last date entered by the user:

See image below:

What Bubble saves in the DB is a Unix time. What you see in human-readable format depends on your time zone.
So, at the moment of me writing this comment the Unix time looks like 1686743036. For my timezone it is 14 Jun 2:43 PM. But for somebody living in New York it will be 14 Jun 7:43 AM

In that case you can just ensure you always use the same time zone for the input date and the date used to calculate the difference.

But we can’t use the same time zone because users come from different countries.

This is how dates are recorded on my database (See image below):

Merci pour votre réponse …

Then just use UTC

although I can’t understand why you can’t just use the User’s time zone?

If I understood you correctly (see image below)…

This user actually entered the date “June 06, 2023 12:00 am”, but Bubble displays the date June 05, 2023 11:00 pm" because of the time zone change?

Oooo this is one of my favorite soapboxes.

There’s generally two approaches to this problem:

  1. use bubble dates and be careful of time zone usage in the app (this has gotten way easier in recent months). In settings, you can enable the ability to override the timezone of your date pickers, pages, and workflows. When you do that, you can pick a specific time zone in all those places. Then you can also display dates back to your users on a specific time zone too using format as. If you always pick utc for instance you can reliably use the date portion.

  2. create a custom data type with one entry per day, and columns for day month and year. Lookup to this whenever you need to store a date. So for instance, a user picks today in a picker and i store the custom value that matches the picker input on day, month, and year

I could (and one day will) do a whole YouTube series on dates, date times, and timezones for developers. Cause this is only the beginning of the things you can think about when it comes to dates!

But also… Live Bubbling with Keith: Let's Talk About Dates - Explaining the Basics of Dates in Bubble

1 Like

Oooo gonna go watch this.

The most recent timezone override features add some extra power too.

1 Like

This is only slightly out of date (as it precedes some Bubble features related to arbitrary date times and timezone overrides), however the core information is still valid as we are just talking about JavaScript date objects and basic concepts like date construction and date formatting, which of source have not changed.

Extremely easy. Use the extract date function in workflow. You can save to a field and subtract them later. I use it to calculate current age, I subtract birthdate that I previously captured from current date and extract month and year to make the calculation of age.
:slight_smile:

extract date 2

and you get this data:
extract date 3

Does that help?

Often, it is just annoying seeing time where only the date is needed. It is often irrelevant and looks bad as well from user prespective.

Why would yo show it to your users?

Good evening;

I want to thank all the friends who participated in the enrichment of this subject “I present my thanks especially to Brian9”.

I found the solution. You just have to use “Rounded down to date” to exclude the time from the calculation (see image below).