Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Function Help

Status
Not open for further replies.
Oct 17, 2006
227


I want to create a simple function that will take the datetime and convert it to
14-AUG-2013.


Now the current select works fine until we get to the start of the month
and it shows

1-AUG-2013

but is there any way to make it show

01-AUG-2103

SELECT DATENAME ( DAY, GETDATE()-13 ) + '-' + UPPER (LEFT (DATENAME(MONTH,( DATEADD(Month, 0,GETDATE() ))) ,3))+ '-'+
DATENAME ( Year,GETDATE() )
 
Not pretty but does the trick !

SELECT CONVERT ( NVARCHAR (2) , GETDATE()-13 , 113) + '-' + UPPER (LEFT (DATENAME(MONTH,( DATEADD(Month, 0,GETDATE() ))) ,3))+ '-'+
DATENAME ( Year,GETDATE() )
 
Try:
Code:
declare @d datetime = '8/1/2013'
select @d, REPLACE(UPPER(CONVERT(varchar(11), @d, 113)),' ', '-')

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 

Try

Code:
REPLACE(UPPER(CONVERT(varchar(11), GETDATE(), 113)), ' ', '-')



Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top