Download presentation
Presentation is loading. Please wait.
1
Temporal Data Part V
2
Temporal Data Types DATE TIMESTAMP Century Year Month Day Hour Minute
Second AM TIMESTAMP Includes DATE Plus Fractional Seconds 0 to 9 – default is 6 AM
3
Temporal Functions TO_DATE(string [, format])
TO_TIMESTAMP(string [, format]) TO_CHAR(temporal_data [, format])
4
Date and Time Formats
5
Date and Time Formats
6
Date and Time Formats
7
Date and Time Formats
8
Back to the Functions SELECT to_char(sysdate, 'DD-MON-YYYY') FROM dual
18-JUL-2019 SELECT to_date('25-DEC :25:23', 'DD-MON-YYYY HH24:MI:SS') FROM dual 12/25/2019 3:25:23 PM
9
More Functions ADD_MONTHS(date_value, months) CURRENT_DATE
Adds months to date_value. Add negative months to subtract. CURRENT_DATE Returns the current date and time as a DATE value SELECT add_months(sysdate, -2) FROM dual 5/18/2019 7:28:26 PM SELECT current_date FROM dual 7/18/2019 7:30:18 PM
10
More Functions LAST_DAY(date_value)
Computes the last day of the month in which the given date_value falls. MONTHS_BETWEEN(later_date, earlier_date) Calculates the number of months between the two given dates. SELECT last_day(sysdate) FROM dual 7/31/2019 7:35:13 PM SELECT months_between(sysdate, to_date('15-JAN-1968', 'DD-MON-YYYY')) FROM dual 618
11
More Functions NEXT_DAY(date, weekday) SYSDATE
Returns the date of the next specified weekday following the given date. SYSDATE Returns the current date and time from the operating system on which the database resides as a DATE value SELECT next_day(sysdate, 'WED') FROM dual 7/24/2019 7:40:06 PM SELECT sysdate FROM dual 7/18/2019 7:41:37 PM
12
Date Addition A number added to a date is assumed by the system to be a number of days. Convert what you want to add to days Add 20 minutes to sysdate: SELECT sysdate + 7 FROM dual 7/25/2019 7:44:36 PM SELECT sysdate + (20/1440) FROM dual 7/18/2019 8:05:28 PM 60 min/hr * 24 hours in a day = 1440
13
Rounding & Truncating Dates
You can round or truncate a date to a specific minute, hour, day, week, quarter, year or century with ROUND or TRUNC respectively. SELECT round(sysdate, 'HH') FROM dual 7/18/2019 8:00:00 PM SELECT trunc(sysdate, 'HH') FROM dual 7/15/2019 7:00:00 PM
14
Rounding & Truncating Dates
15
Rounding & Truncating Dates
16
Rounding & Truncating Dates
SELECT * FROM sprhold WHERE trunc(sprhold_activity_date) = to_date('09-APR-2019', 'DD-MON-YYYY')
17
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.