Thursday, April 25, 2013

CHECK TODAY IS SATURDAY OR SUN DAY in SQL SERVER 2012.

CHECK TODAY IS SATURDAY OR SUN DAY in SQL SERVER 2012.


The following script gets today's date using getdate() function.
Format function return Short day of the today's date. and If condition checks if today's day falls in Sat/sun. Displays appropriate message.

 


declare @today varchar(3);
set @today = FORMAT(getdate(),'ddd') --ddd gives short day.
select @today  --display

if( @today in ('Sat','Sun'))
print 'Today is '+@today
else print 'Today is not saturday/sunday but '+@today+' day';


OUTPUT:  if Today is Friday

Today is not saturday/sunday but Fri day

ex 2: if Today is Saturday

Today is Sat.


Tags: CHECK TODAY IS SATURDAY OR SUN DAY in SQL SERVER 2012. Display Day in short form, using Format Function in SQL Server, T-SQL IN clause,Using T-SQL IF condition,

No comments:

Post a Comment