-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-date-time-types.sql
More file actions
28 lines (22 loc) · 882 Bytes
/
Copy path03-date-time-types.sql
File metadata and controls
28 lines (22 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- Date and Time Data Types in SQL
-- These data types are used for storing date, time, and timestamp data.
-- 1. DATE:
-- Stores date values (year, month, day).
-- Example:
SELECT CAST('2025-04-28' AS DATE) AS Example_Date;
-- 2. DATETIME:
-- Stores date and time values (year, month, day, hour, minute, second).
-- Example:
SELECT CAST('2025-04-28 14:30:00' AS DATETIME) AS Example_Datetime;
-- 3. TIMESTAMP:
-- Similar to DATETIME, but automatically updated with the current timestamp when a record is modified.
-- Example:
SELECT CURRENT_TIMESTAMP AS Example_Timestamp;
-- 4. TIME:
-- Stores time values (hour, minute, second).
-- Example:
SELECT CAST('14:30:00' AS TIME) AS Example_Time;
-- 5. DATETIME2 (SQL Server only):
-- A more precise version of DATETIME.
-- Example:
SELECT CAST('2025-04-28 14:30:00.1234567' AS DATETIME2) AS Example_Datetime2;