Blog Stats
  • Posts - 12
  • Articles - 0
  • Comments - 115
  • Trackbacks - 0

 

Date Custom Format - SQL Server

As everyone knows, DATE can be formatted in different ways and the usual way will be using CONVERT

Syntax:

SELECT CONVERT(VARCHAR(30), GETDATE(), 106)

Where as 106 can be replaced by 101, 110, etc according to the requirements.

Custom Format:

If we need custom date format(19-March-2009), which is not a pre-defined format in CONVERT, then consider the below:

Syntax:
SELECT DATENAME(DAY,GETDATE()) + '-' + DATENAME(MONTH,GETDATE()) + '-' + DATENAME(YEAR, GETDATE())

I know, this is just a small thing. But still it might help someone who is in search of requirement like this !

Feedback

# re: Date Custom Format - SQL Server

Gravatar We feel make money in Indian Stock MArket then buy some gadgets 3/22/2009 1:31 AM | BullRider

# re: Date Custom Format - SQL Server

Gravatar Thanks for this - took a bit of googling (given that im still learning sql) to work out how to custom format the date and your solution solved it for me.

Your code worked a treat.

Thanks,
5/14/2009 12:49 AM | Joel Webb

# re: Date Custom Format - SQL Server

Gravatar God to find the date syntax for your site.

TradingCalls

www.GoldTradingCalls.com 9/13/2009 11:28 PM | Venkat

# re: Date Custom Format - SQL Server

Gravatar Excellent, thank you very much. 1/17/2012 3:04 AM | Chris Rumsey

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © nagendraprasad