Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts for DATETIME vs DATETIME2 in SQL Server #126

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DECLARE @date1 DATETIME;
SET @date1 = GETDATE();
SELECT @date1 + 1 as Tomorrow;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DECLARE @datetime2 DATETIME2(7), @datetime DATETIME;
SET @datetime2 = '2024-08-06 18:34:10.2333333';
SET @datetime = '2024-08-06 18:34:10.233';
SELECT @datetime AS 'datetime', @datetime2 AS 'datetime2';
12 changes: 12 additions & 0 deletions sql-queries-dates/sql-datetime-vs-datetime2/datetime-variable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DECLARE @date1 DATETIME = '2024-08-15 10:30:00';

CREATE TABLE Appointments (
AppointmentDate DATETIME
);

INSERT INTO Appointments (AppointmentDate)
VALUES (@date1);

SELECT AppointmentDate
FROM Appointments
WHERE AppointmentDate = @date1;
10 changes: 10 additions & 0 deletions sql-queries-dates/sql-datetime-vs-datetime2/datetime.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE Appointments (
AppointmentDate DATETIME
);

INSERT INTO Appointments (AppointmentDate)
VALUES ('2024-08-15 10:30:00.000');

SELECT AppointmentDate
FROM Appointments
WHERE AppointmentDate = '2024-08-15 10:30:00.000';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DECLARE @date2 DATETIME2 = '2022-01-01 12:30:00.1234567';
SELECT @date2;
10 changes: 10 additions & 0 deletions sql-queries-dates/sql-datetime-vs-datetime2/datetime2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE Events (
EventTime DATETIME2
);

INSERT INTO Events (EventTime)
VALUES ('2024-08-05 10:30:00.12345');

SELECT EventTime
FROM Events
WHERE EventTime = '2024-08-05 10:30:00.12345';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DECLARE @date1 datetime, @date2 datetime2(3);
SET @date2 = '2024-12-03 11:25:20.5782441';
SET @date1 = @date2;
SELECT @date1 AS 'datetime', @date2 AS 'datetime2';