/ Published in: SQL
SQL Server 2008 Date/Time Statements
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
-- 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()))