Date Time Tips & Tricks
In this Date Time Tips & Tricks article, we cover some ways that you can get more out of the Date Time variable and Back-end Time Events inside of Dittofi.
In this article you will learn about:
- Current Time
- Date Time Variable
- Storing Date Time
- Date Time Comparisons
- Doing Date Time Math
Current Time
Dittofi provides a DateTime variable that allows you to get the current date and time in UTC (Coordinated Universal Time). The video below shows you how you can set the current time when a record was created inside of your database and also how you can set the time when a record was last updated.
Date Time Variable
When we ran the endpoint in the example above, you saw that the date time value that was returned to the endpoint looked something like this:
The format of the date time is in nanoseconds. You will also notice that there is a “T” and a “Z” that are added to the times value. The “T” doesn’t really mean anything. It is just the standard programmatic way to separate the date from the time (here is an article on the programming standard, if you’re interested). The “Z” on the other hand stands for “Zulu Time Zone”, which is a military timezone that is UTC+0. Often programmers mistake the Z for meaning “Zero Time Zone”, but this is incorrect.
The generated code is in Google Go or golang code, so it uses the standard golang time package. If you’re interested, you can read more about how it works within the Google Go docs.
You can see the generated code for this function by clicking on the “View Code” button within your action and reading the line highlighted below.
Storing Date Time
There are several ways to store date time values however, the recommended way inside of Dittofi is to use the Date Time variable type.
To set this up within the Data Models page, you need to (1) add a new column to your Data Table and (2) choose the Date Time option for your variable type.
Notice, you can choose the format of the date as well as set default values for the Date Time.
Date Time Comparisons
Date time comparisons can be used to check if something happens before or after a particular event. For example, let’s say that we have a list of “upcoming events” and we want to loop through these events and find those events that are happening within the next 7 days. To do this we need to use date time comparisons. The video below explains how to set this up inside of Dittofi.
Doing Date Time Math
We’ve actually already done a bit of date time math in our last example where we added seven days to the current date and time. This can be really useful to get things like “upcoming events” or if you want to send out an alert such as an email trigger notification based on time.
For a full reference guide for the Time Events see our reference docs.