Monday, August 21, 2017

sql server get time if the field contains today date else select date with out time format in datetime field

Problem :

i need to get time for message if it sent today else i  need to get the date of message with out time.

query :
select case when cast([CreateDate] as date) = cast(GETDATE() as date)
            then CONVERT(varchar(15),CAST([CreateDate] AS TIME),100)
            else CONVERT(varchar(15),CAST([CreateDate] AS date),100)
      end
from [MOAKPIS].[dbo].[Notifications];


output

No comments:

Post a Comment