This example illustrates how the NOW
and TODAY
functions operate. Both functions generate outputs of Datetime data type.
NOW
- Generates valid Datetime values for the current timestamp in the specified time zone. See NOW Function.TODAY
- Generates valid Datetime for the current date in the specified time zone. See TODAY Function.DATEDIF
- Calculates the difference between two Datetime values based on a specific unit of measure. See DATEDIF Function.Source:
The following table includes flight arrival information for Los Angeles International airport.
FlightNumber | Gate | Arrival |
---|---|---|
1234 | 1 | 2/15/17 11:35 |
212 | 2 | 2/15/17 11:58 |
510 | 3 | 2/15/17 11:21 |
8401 | 4 | 2/15/17 12:08 |
99 | 5 | 2/16/17 12:12 |
116 | 6 | 2/16/17 13:32 |
876 | 7 | 2/15/17 16:43 |
9494 | 8 | 2/15/17 21:00 |
102 | 9 | 2/14/17 19:21 |
77 | 10 | 2/16/17 12:31 |
Transformation:
You are interested in generating a status report on today's flights. To assist, you must generate columns with the current date and time values:
Tip: You should create separate columns containing static values for |
Next, you want to identify the flights that are landing today. In this case, you can use the DATEDIF
function to determine if the Arrival
value matches the currentTime
value within one day:
NOTE: The |
Since you are focusing on today only, you can remove all of the rows that do not apply to today:
Now focusing on today's dates, you can calculate the difference between the current time and the arrival time by the minute:
Using the numeric values in the status
column, you can compose the following transform, which identifies status of each flight:
Results:
You now have a daily flight status report:
currentDate | currentTime | FlightNumber | Gate | Arrival | status | today |
---|---|---|---|---|---|---|
2017-02-15 | 2017-02-15·11:46:12 | 1234 | 1 | 2/15/17 11:35 | landed | 0 |
2017-02-15 | 2017-02-15·11:46:12 | 212 | 2 | 2/15/17 11:58 | arriving | 0 |
2017-02-15 | 2017-02-15·11:46:12 | 510 | 3 | 2/15/17 11:21 | arrived | 0 |
2017-02-15 | 2017-02-15·11:46:12 | 8401 | 4 | 2/15/17 12:08 | scheduled | 0 |
2017-02-15 | 2017-02-15·11:46:12 | 876 | 7 | 2/15/17 16:43 | scheduled | 0 |
2017-02-15 | 2017-02-15·11:46:12 | 9494 | 8 | 2/15/17 21:00 | scheduled | 0 |
2017-02-15 | 2017-02-15·11:46:12 | 102 | 9 | 2/14/17 19:21 | arrived | 0 |
The currentDate
, currentTime
, and today
columns can be deleted.