Home > Transact-SQL > Transact-SQL: How to get current date with start time 00:00:00 and end time 23:59:59

Transact-SQL: How to get current date with start time 00:00:00 and end time 23:59:59

18:31

Marek Śliwiński Leave a comment Print This Post  (129) Go to comments
--SQL Server stores milliseconds with a precision of 1/300ths of a second.
-- So in other words, milliseconds are stored as:
--.000
--.003
--.007
--.010
--.013
--.017
-- etc.

SET DATEFIRST 1
SET DATEFORMAT ymd

SELECT
    DATEADD(ms, 0, CONVERT(varchar(10), GETDATE(), 120)) as 'StartToday'
    ,DATEADD(ms, -3, CONVERT(varchar(10), GETDATE()+1, 120)) as 'EndToday'

Result:

StartToday              EndToday
----------------------- -----------------------
2008-09-22 00:00:00.000 2008-09-22 23:59:59.997

(1 row(s) affected)
Share and Enjoy:
  • DotNetKicks
  • Digg
  • del.icio.us
  • Wikio IT
  • Google Bookmarks
  • Facebook
  • Print
  1. No comments yet.
  1. No trackbacks yet.

Subscribe without commenting