dotnet-practitioner
dotnet-practitioner

Reputation: 14148

getdate tsql question

How do I write TSQL that it calculates the following:

  1. the current date and mid night such as 2010-12-01 00:00:00.000
  2. the current date and 6pm such as 2010-12-01 18:00:00.000

Thanks..

Upvotes: 4

Views: 323

Answers (2)

Joel Coehoorn
Joel Coehoorn

Reputation: 415810

  1. dateadd(dd,datediff(dd,0, getDate()),0)
  2. dateadd(hh,18 + (24 *datediff(dd,0, getDate())),0)

Upvotes: 4

bobs
bobs

Reputation: 22184

You can try something like the following

SELECT DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0) AS DateNoTime, 
    DATEADD(hh, 18, DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0)) AS DateNewTime

Upvotes: 4

Related Questions