# How is time stored?

**URL:** <https://forum.bubble.io/t/how-is-time-stored/39445>\
**Category:** Need help\
**Created:** [October 7, 2018, 11:07pm UTC](https://forum.bubble.io/t/how-is-time-stored/39445 "2018-10-07T23:07:05Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![keith](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/keith/32/56020_2.png) [@keith](https://forum.bubble.io/u/keith)\
**Post date:** [October 8, 2018, 2:23am UTC](https://forum.bubble.io/t/how-is-time-stored/39445/3 "2018-10-08T02:23:46Z")

</div>

What @mebeingken says is all true. Additionally: Bubble essentially makes nodejs applications. Nodejs is just JavaScript, really. Dates in Bubble are just JavaScript dates (by which I mean the date data type is exactly the JavaScript date data type).

You are now saying, “I asked about time, not dates.” Times ARE dates. Dates in JavaScript always have a time component (as they should actually, even though this perplexes folks). So, just like in JS, you will use dates and date manipulation functions to deal with time.

Scheduling apps are NOT the easiest thing to build if you have no familiarity with how dates and times (the same thing, really, date/times as I tend to call them) work in computing and in JS in particular.

You’ll want to understand JS date objects (start here: [JavaScript Date Objects](https://www.w3schools.com/js/js_dates.asp)).

You can learn a lot about date/time and date/time related issues by reading the docs for a package called moment and its extension moment-timezone: [https://momentjs.com/](https://momentjs.com/)

It seems clear that Bubble uses moment and moment timezone (and likely the moment-range package) to do many of its date/time related operations, though this hasn’t been confirmed here in the forum.

Bubble’s date/time manipulation functions are quite extensive (though not all capabilities of moment and moment-timezone are exposed to you the programmer/user, which is frankly infuriating but understandable).

**Anyway @ezra, times are stored in Bubble just like they are in JavaScript, as date objects (objects with a data type of “date”).**

There are, further (because you will need them), date range and date interval types available to you.

Here’s a quick rundown of what these data types represent:

DATE: A date describes **a unique point in time**. “Current date/time” is an example (representing “now”).

DATE RANGE: A date range describes **a unique time period**. “Current date/time\<-range-\>Current date/time:plus days 5” is an example (representing now until 5 days from now).

DATE INTERVAL: A date interval describes the **duration** of a **unique time period**. The _interval_ – the _duration_ – itself is of course not unique. (5 seconds is just 5 seconds. But to construct a date interval you must first assume some unique time period like “Now until 5 minutes from now”. Now you have a date interval of 5 minutes duration. You could compare that to other intervals created from other unique date/times.) “Current date/time:plus seconds 5 - Current date/time” is an example (representing 5 seconds, the duration between now and 5 seconds from now – “duh”, I know).

So, the answer to “how exactly is time stored?” is “well, what sort of time are you attempting to store?” In Bubble, you have three options at present.

I take your question to mean, “how would I go about storing ‘30 minutes’ in Bubble?” Well, that’s a value of date interval type.

However, you will need all of these things in order to build your scheduling app. Another quick primer:

Let us say we want to make an APPOINTMENT object. (An object of Appointment data type which represents the creator of that object being “unavailable for your stupid request to meet with me and waste my valuable time”, right?)

That object will obviously have a start date and an end date (even if we assume this “Appointment” happens every day). Those are unique points in time.

That object has an implied (or you can make it explicitly stored) range: Appointment’s:start date ← range -\>Appointment’s end date. Ranges have special operations which can tell you if some requested range is :contained by or :overlaps or other things with somebody’s request. You’ll need that.

That Appointment object also has an implied duration. (Again, you could explicitly store that if you wish – it may be more performant depending upon how often you need to compute that duration.) The duration is an interval constructed as Appointment’s end date - Appointment’s start date. (As an example, if the end is 45 minutes after the start, the duration is 45 minutes, eh?)

For more on all of this, search for any post where I’ve mentioned “date” or “date/time”. More on date ranges and how you should think about them (and what we can DO with them) can be found here:

> [@How to use the range funtions - e.g of how to use it](http://forum.bubble.io/t/how-to-use-the-range-funtions-e-g-of-how-to-use-it/37042/7):
>
> OK: A Quick Primer on Date Ranges What is a date? You are probably familiar with the date data type. A date describes a unique point in time. (Remember: Whenever we are talking about “dates”, we are actually talking about date/time objects. When we casually say “date” we should always remember that what we are saying is “a date/time”.) A date represents some point in time. A date may be before some other date (in which case it is “in the past” with respect to some other date and would be “le…

I’ve not written much about date intervals. Intervals are not particularly interesting (though very useful) and – I gotta say – are probably misnamed. I’ve started to see people ask here about “how do I store 5 minutes?” (for example). The answer is as a date interval. Should “date intervals” be called “time”? I dunno… maybe. But Bubble nomenclature is (1) generally bad and (2) always evolving.

Anyway, if you read the post I link to above, you’ll start to understand further the use of various date representations. (The main thing is that they have different operators and different meanings for operations like less than, greater than, etc.)

I was going to stop here, but eff it… I’ll go on. Here’s why this is useful and important. Let’s consider what “less than” and “greater than” mean with respect to all three of the date/time data types:

1. What does it mean for a date (a unique _point in time_) to be \< or \> some other date?

A date is \< some\_other\_date if date occurs _in the past_ with respect to some\_other\_date.  
A date is \> some\_other\_date if date occurs _in the future_ with respect to some\_other\_date.

**2. What does it mean for a date range (a unique time _period_) to be \< or \> some other date range?**

Trick question. There aren’t such operators for date ranges. Date ranges instead have a variety of states with respect to some other range:

A date\_range _is before_ some\_other\_date\_range if date\_range’s end is in the past with respect to some\_other\_date\_range’s start.

A date\_range _is after_ some\_other\_date\_range if date\_range’s start is in the future with respect to some\_other\_date\_range’s end.

A date\_range _overlaps_ some\_other\_date\_range if date\_range’s start is between some\_other\_date\_range’s start and end OR if date\_range’s end is between some\_other\_date\_range’s start and end. (i.e., if it partly runs over – either on the start side or end side, or FULLY RUNS OVER – some\_other\_date\_range)

A date\_range _is contained by_ some\_other\_date\_range if date\_range’s start is after some\_other\_date\_range’s start AND date\_range’s end is before some\_other\_date\_range’s end. (i.e., if it is fully enclosed by some\_other\_date\_range)

If date\_range is contained by some\_other\_date\_range, we can conversely say that some\_other\_date\_range _contains_ date\_range, BTW.

**3. What does it mean for a date interval to be \< or \> some other date interval?**

This one is a lot easier (compared to #2 above). You can think about date intervals as being simple decimals, but decimals of time. I believe the resolution is milliseconds.

So, date\_interval \< some\_other\_date\_interval if the number of ms represented by date\_interval is less than the number of ms represented by some\_other\_date\_interval.

Similarly, date\_interval \> some\_other\_date\_interval if the number of ms represented by date\_interval is greater than the number of ms represented by some\_other\_date\_interval.

**There’s a great deal more we can say about times and dates, but this will get you started!**

---

_[View the full topic](https://forum.bubble.io/t/how-is-time-stored/39445)._
