Return to Snippet

Revision: 59916
at April 2, 2013 09:30 by msstar


Updated Code
-- FIRST DAY OF MONTH
SELECT DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)

-- LAST DAY OF MONTH
SELECT DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,GETDATE())+1,0))

-- GET UTC TIME DIFFERENCE
DATEDIFF(DAY, GETUTCDATE(), GETDATE());

-- GET 12 HOURS TIME FORMAT (i.e 8:07PM)
SELECT SUBSTRING(CONVERT(VARCHAR,GETDATE(),100),12,8)

-- GET 24 HOURS TIME FORMAT (i.e 23:37)
SELECT CONVERT(VARCHAR(5),GETDATE(),108)

-- GET TIME DIFFERENCE BETWEEN 2 TIMES
SELECT DATEDIFF(HH,TIME1,TIME2)

-- SEARCH IF MORE THAN ONE RECORD EXISTS
SELECT CLIENT FROM PROP_X_CLIENT_JOB
GROUP BY CLIENT
HAVING COUNT(*) > 1

-- GET CURRENT DATE ONLY DATE PART
SELECT DATEADD(DD,0,DATEDIFF(DD,0,GETDATE()))

Revision: 59915
at December 20, 2012 09:59 by msstar


Updated Code
-- FIRST DAY OF MONTH
SELECT DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)

-- LAST DAY OF MONTH
SELECT DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,GETDATE())+1,0))

-- GET UTC TIME DIFFERENCE
DATEDIFF(DAY, GETUTCDATE(), GETDATE());

-- GET 12 HOURS TIME FORMAT (i.e 8:07PM)
SELECT SUBSTRING(CONVERT(VARCHAR,GETDATE(),100),12,8)

-- GET 24 HOURS TIME FORMAT (i.e 23:37)
SELECT CONVERT(VARCHAR(5),GETDATE(),108)

-- GET TIME DIFFERENCE BETWEEN 2 TIMES
SELECT DATEDIFF(HH,TIME1,TIME2)

-- SEARCH IF MORE THAN ONE RECORD EXISTS
SELECT CLIENT FROM PROP_X_CLIENT_JOB
GROUP BY CLIENT
HAVING COUNT(*) > 1

Revision: 59914
at November 9, 2012 16:16 by msstar


Updated Code
-- FIRST DAY OF MONTH
SELECT DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)

-- LAST DAY OF MONTH
SELECT DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,GETDATE())+1,0))

-- GET UTC TIME DIFFERENCE
DATEDIFF(DAY, GETUTCDATE(), GETDATE());

-- GET 12 HOURS TIME FORMAT (i.e 8:07PM)
SELECT SUBSTRING(CONVERT(VARCHAR,GETDATE(),100),12,8)

-- GET 24 HOURS TIME FORMAT (i.e 23:37)
SELECT CONVERT(VARCHAR(5),GETDATE(),108)

-- GET TIME DIFFERENCE BETWEEN 2 TIMES
SELECT DATEDIFF(HH,TIME1,TIME2)

Revision: 59913
at November 7, 2012 11:45 by msstar


Updated Code
-- FIRST DAY OF MONTH
SELECT DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)

-- LAST DAY OF MONTH
SELECT DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,GETDATE())+1,0))

-- GET UTC TIME DIFFERENCE
DATEDIFF(DAY, GETUTCDATE(), GETDATE());

-- GET 12 HOURS TIME FORMAT (i.e 8:07PM)
SELECT SUBSTRING(CONVERT(VARCHAR,GETDATE(),100),12,8)

-- GET 24 HOURS TIME FORMAT (i.e 23:37)
SELECT CONVERT(VARCHAR(5),GETDATE(),108)

Revision: 59912
at October 9, 2012 20:08 by msstar


Updated Code
-- FIRST DAY OF MONTH
SELECT DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)

-- LAST DAY OF MONTH
SELECT DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,GETDATE())+1,0))

-- GET UTC TIME DIFFERENCE
DATEDIFF(DAY, GETUTCDATE(), GETDATE());

-- GET 12 HOURS TIME FORMAT (i.e 8:07PM)
SELECT SUBSTRING(CONVERT(VARCHAR,GETDATE(),100),12,8)

Revision: 59911
at October 9, 2012 10:46 by msstar


Updated Code
-- FIRST DAY OF MONTH
SELECT DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)

-- LAST DAY OF MONTH
SELECT DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,GETDATE())+1,0))

-- GET UTC TIME DIFFERENCE
DATEDIFF(DAY, GETUTCDATE(), GETDATE());

Revision: 59910
at October 9, 2012 10:38 by msstar


Updated Code
-- FIRST DAY OF MONTH
SELECT DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)

-- LAST DAY OF MONTH
SELECT DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,GETDATE())+1,0))

Revision: 59909
at October 9, 2012 10:37 by msstar


Initial Code
-- FIRST DAY OF MONTH
SELECT DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)
-- LAST DAY OF MONTH
SELECT DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,GETDATE())+1,0))

Initial URL

                                

Initial Description
SQL Server 2008 Date/Time Statements

Initial Title
SQL Date/Time Statements

Initial Tags
sql

Initial Language
SQL