WEBVTT

00:00.730 --> 00:07.030
The interval data type is useful for easy to understand calculations on date and time data.

00:07.060 --> 00:12.220
For example, let's say you have a column that holds the date a client signed a contract.

00:12.220 --> 00:18.820
So using interval data, you can add 90 days to each contract date to determine when to follow up with

00:18.820 --> 00:19.600
the client.

00:19.630 --> 00:25.060
So to see interval how interval data type works, we will use.

00:26.160 --> 00:29.700
Uh, date time types table.

00:30.580 --> 00:32.020
That we have just created.

00:32.030 --> 00:33.700
Let's actually hear.

00:34.580 --> 00:35.930
Date time type state.

00:36.060 --> 00:41.780
Table that we just created column interval we have just two columns, interval, column and timestamp

00:41.780 --> 00:42.830
column and interval column.

00:43.190 --> 00:51.200
And here we have we will write select timestamp, column and interval column.

00:51.200 --> 00:57.620
And after that we will add timestamp column minus negative here.

00:57.620 --> 01:00.620
Interval column.

01:00.920 --> 01:02.750
Actually, let's go to new line.

01:02.750 --> 01:03.440
So.

01:04.220 --> 01:05.160
And have a column.

01:05.580 --> 01:09.990
And after that, we will add a timestamp column minus.

01:10.020 --> 01:11.250
Interval.

01:11.280 --> 01:15.870
Column as new date from.

01:17.080 --> 01:17.830
From.

01:20.610 --> 01:21.120
Date.

01:22.230 --> 01:23.580
Time, times.

01:23.820 --> 01:24.660
That's it.

01:25.200 --> 01:25.920
Let's run it.

01:26.970 --> 01:28.590
They have a time lapse.

01:31.630 --> 01:31.960
Here.

01:32.440 --> 01:39.310
So this is a typical select statement, except we will compute a column called New Date here.

01:40.180 --> 01:41.740
Uh, that contains.

01:42.800 --> 01:50.120
And it contains the result of timestamp columns minus interval column and composite columns are called

01:50.120 --> 01:52.420
expressions, and we will use this technique often.

01:52.430 --> 01:58.400
So in each row we subtract the unit of time indicated by the interval data type from the date.

01:58.400 --> 02:02.840
So this produces the result here, as you can see here.

02:02.900 --> 02:11.300
So also keep in mind that new date column by default is formatted as a timestamp with time zone allowing

02:11.300 --> 02:17.660
for the display of time values as well as the dates if the interval values uses them.

02:18.850 --> 02:19.600
So.

02:20.770 --> 02:26.170
You can see the data type listed in the Pgadmin results crate listed beneath the column names here.

02:26.990 --> 02:31.640
Again, your output may be different based on your time zone.
