November 12th, 2008

Sample Data Type Values

Posted by admin in F. Data Types

November 11th, 2008

DATE/TIME/INTERVAL Data Arithmetic

Posted by admin in F. Data Types

Many RDBMS systems have their own functions for date/time math.
You can generally perform the following operations:> Subtract two date/times to get an interval.
> Add or subtract an interval and a date/time to get a future or past date/time.
> Add or subtract two Intervals to get a new Interval.
> Multiply or divide an Interval by a number to get a new Interval.

Adding two dates makes no sense.

EXTRACT() can be used to retrieve a single field from a date, time, or timestamp.

> Access and SQL Server have a DATEDIFF() function.
> MySQL has DATE_ADD() and DATE_SUB() functions.
> Oracle has an ADD_MONTHS() function.

November 10th, 2008

DAY HOUR MINUTE SECOND Data, Part 2 of 2

Posted by admin in F. Data Types

If precision is specified, it shows the number of positions in the field:

INTERVAL HOUR(2)                     Means 2 digits for the hour.
                                     This is also the default length for HOUR
                                     if precision is omitted.
INTERVAL SECOND(5,3)                 Means 5 digits for the second
                                     and 3 digits for the fractional second.
                                     6 is the default fractional precision of second
                                     if the fractionalprecision is omitted.
INTERVAL DAY(5) TO MINUTE            Means 5 digits for DAY,
                                     and values of HOUR and MINUTE.
INTERVAL MINUTE(5) TO SECOND(4)      Means 5 digits for MINUTE and 4 digits for SECOND.
INTERVAL '21:17:7.2' 21 hours,       17 minutes,7.2 seconds.
INTERVAL '21:17:7.2' HOUR TO SECOND  21 hours, 17 minutes, 7.2 seconds.

Changing a time with an INTERVAL:

NewTime = DueTime + INTERVAL '30' MINUTE

Finding the number of hours between two times:

TimeLate = (TimePaid - DueTime) HOUR

A time can have it’s time zone specified:

TIME '15:45:30'                         AT LOCAL (AT LOCAL means that
                                        this time is in the local time zone.)
INTERVAL '10' DAY + INTERVAL '15' DAY   Gives an interval of '25' days.
Next Page »