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)
=CONVERT(VARCHAR(7), GETDATE(), 120)and
RefId is NULL Order By Id DESC

Date Formate
SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), ' ', '-') 
AS [DD-Mon-YYYY]
OP:25-Dec-2009
Advertisements

2 Responses to “Some usefull syntax with date in sql server.”

  1. Sharath Says:

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

    • Chandra Dev Says:

      Thank you.


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: