Date extracting

  • I would like to return an datetime field as Date and the Hour segment with the Minute segment always set to '00' ?

  • select cast((convert(varchar(4), DATEPART( yy , getdate())) + '-' +

    convert(varchar(2), DATEPART(mm , getdate())) + '-' +

    convert(varchar(2), DATEPART(dd , getdate())) + ' ' +

    convert(varchar(2), DATEPART(hh , getdate())) + ':' + '00:00') as datetime)

  • Here is another alternative:

    select cast((convert(char(13),getdate(),120) + ':00:00.000') as datetime)

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply