UMBC CMSC 461 Fall '98 

CSEE | 461 | 461 F'98 | lectures | news | help 


Lecture 25 
Additional Date and Time Information

Time in Databases

Normally, databases only only model one state of the real world outside -- the current state.  Sometimes it is desirable to have information on past states.  These are called temporal databases.  For example, a factory monitoring system will hold past readings as well as current readings for long term analysis.
 

Time Specifications in SQL-92

The SQL-92 standard defines date, time, and timestamp.  Date and time are obvious, but timestamp contains date and time.  There is also a way to include the time zone.  Additionally, there is what is called UTC (Universal Coordinated Time), which is the military is referred to as "Zulu" time or Greenwich Mean Time (GMT).  The world clock is defined by what time it is in Greenwich, England, which is where this time system was invented.  Additionally, there is a data type call interval, which the the span of time between two points on the time line.

Date Formats

Date Formats

Format

Description

Example

MM

Number

7

MON

3-Letter abbrev of month

JAN

MONTH

Fully spelled out month

JANUARY

D

Number of day in the week

3

DD

Number of day in the month

16

DDD

Number of day in the year

234

DY

3-Letter abbrev of day of the week

WED

DAY

Fully spelled out day of the week

WEDNESDAY

Y

Last digit of the year

8

YY

Last two digits of the year

98

YYY

Last three digits of the year

998

YYYY

Full four digits of the year

1998

HH12

Hours of the day (1 to 12)

10

HH24

Hours of the day (1 to 24)

17

MI

Minutes of the hour

34

SS

Seconds of minute

35

AM

Displays AM or PM depending on the time

AM

     

 

Date Functions

Examples

select hdate, sysdate, hdate+2, hdate-2, sysdate-hdate
from employees;

insert into employees hdate
values ( to_date( '12-JAN-99 02:45:30', 'DD-MON-YY HH:MI:SS' );

select to_char(hdate, 'DD-MONTH-YYYY', )
from employees;


CSEE | 461 | 461 F'98 | lectures | news | help