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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date functions 1

Status
Not open for further replies.

cisco999

Programmer
Apr 26, 2001
66
0
0
US
How do I convert this:
02/13/2003 to 03^02^13

I've used the str & datepart functions to get:
2003^ 2^ ^13
Almost there but not quite.

Appreciate your help!
 
this should work

RIGHT(CAST(Year(CreateDate) AS VARCHAR), 2)+'^'+
CASE WHEN Month(CreateDate) <= 9 THEN '0' ELSE '' END+ CAST(Month(CreateDate) AS VARCHAR)+'^'+
CASE WHEN Day(CreateDate) <= 9 THEN '0' ELSE '' END+ CAST(Day(CreateDate) AS VARCHAR)
 
Thanks! That worked! You are bad to the bone!
Was a lot easier in Oracle though...
 
This is an alternative method:

Code:
REPLACE(CONVERT(varchar(8), getdate(), 2), '.', '^')

Using the CONVERT function with style 2 gets the date in yy.mm.dd format. Then you use REPLACE to change the symbols. --James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top