November 7th, 2008

DAY HOUR MINUTE SECOND Data, Part 1 of 2

Posted by admin in F. Data Types

The day-time interval has to do with the difference between times and contains a day value, an hour value, a minute value, a second value, or some combinations of these.

Some sample formats are:

INTERVAL DAY
INTERVAL DAY(precision)
INTERVAL HOUR
INTERVAL HOUR(precision)
INTERVAL MINUTE
INTERVAL MINUTE(precision)
INTERVAL SECOND
INTERVAL SECOND(fractional_precision)
INTERVAL DAY TO HOUR
INTERVAL DAY(precision) TO HOUR
INTERVAL DAY TO MINUTE
INTERVAL DAY(precision) TO MINUTE
INTERVAL DAY TO SECOND
INTERVAL DAY(precision) TO SECOND
INTERVAL DAY(precision) TO SECOND(fractional_precision)
INTERVAL HOUR TO SECOND
...
INTERVAL HOUR(precision) TO SECOND
...
INTERVAL MINUTE(precision) TO SECOND(fractional_precision)
...
etc.
November 6th, 2008

YEAR MONTH Data

Posted by admin in F. Data Types

The year-month interval has to do with the difference between dates and contains a year value, a month value, or both.

The formats are:

INTERVAL YEAR
INTERVAL YEAR(precision)
INTERVAL MONTH
INTERVAL MONTH(precision)
INTERVAL YEAR TO MONTH
INTERVAL YEAR(precision) TO MONTH

Examples:

INTERVAL '12-7'                  12 years and 7 months.
INTERVAL '12-7' YEAR TO MONTH    12 years and 7 months.

Changing a date with an INTERVAL:

NewDate = DueDate + INTERVAL '7' DAY

Finding the number of days between two dates:

DaysLate = (DatePaid - DueDate) DAY
(DATE '2056-03-20' - DATE '2055-01-10') YEAR TO MONTH = '0001-02' (Or 1 year and 2 months.)
November 5th, 2008

INTERVAL Data

Posted by admin in F. Data Types

An interval is the difference between two datetime values.
In many applications that use dates and times, you sometimes need to determine the interval between two dates or times.
An interval contains the amount of time between two date/time values.
An interval can be used to increase or decrease the value of a date or time.
While various RDBMS systems have their own unique functions to handle these intervals, SQL defines two distinct types of intervals: the year-month interval and the day-time interval.A year-month interval contains the number of whole years and months between two dates.

A day-time interval contains the number of days, hours, minutes, and seconds between two times.

A multiple field qualifier is stated:           INTERVAL start_field TO end_field
where start_field can be YEAR, DAY, HOUR, or MINUTE,
and the end_field can be YEAR, MONTH, DAY, HOUR, MINUTE, or SECOND.
Start_field must be smaller than end_field.
Start_field can have a precision, but end_field can only have a fracional-precision on SECOND.

> You can not add two dates because it makes no sense and SQL will not allow it.
> You can do calculations with intervals.
> Intervals can be added or subtracted.
> Interval field separators are the same as date/time field separators.
> When doing calculations, you can not mix year-month interval calculations with day-time interval calculations because months come in varying lengths of 28, 29, 30, and 31 days.
> INTERVAL is not supported by Access, DB2, MySQL, or SQL Server.

« Previous PageNext Page »