Some usefull syntax with date in sql server.

select convert(varchar,getdate(),101)
OutPut:- 06/18/2008

select convert(varchar,getdate(),102)
OutPut:- 2008.06.18

select convert(varchar,getdate(),103)
OutPut:- 18/06/2008

select convert(varchar,getdate(),104)
OutPut:- 18.06.2008

select convert(varchar,getdate(),105)
OutPut:- 18-06-2008

select convert(varchar,getdate(),106)
OutPut:- 18 Jun 2008

select convert(varchar,getdate(),107)
OutPut:- Jun 18, 2008

select convert(varchar,getdate(),108)
OutPut:- 10:53:20

select convert(varchar,getdate(),109)
OutPut:- Jun 18 2008 10:53:30:507AM

select convert(varchar,getdate(),110)
OutPut:- 06-18-2008

select convert(varchar,getdate(),111)
OutPut:- 2008/06/18

select convert(varchar,getdate(),112)
OutPut:- 20080618

select convert(varchar,getdate(),113)
OutPut:- 18 Jun 2008 10:54:01:253

select convert(varchar,getdate(),114)
OutPut:- 10:54:08:473

select convert(varchar,getdate(),120))
OutPut:- 2008-06-18 10:54:15

Fetching data on basis of Month and Year selection
Select *from tblBuy where Year(EndDate)=2010 and Month(EndDate)=9

Fetching data of Current Month and Year
Select *from tblBuy where Convert(Varchar(7),EndDate,120)
RefId is NULL Order By Id DESC

Date Formate

2 thoughts on “Some usefull syntax with date in sql server.

  1. Sharath January 20, 2011 / 5:59 am

    Good one..!! keep posting…!!!:)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.