Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DATE Cast

Author  Topic 

kdnichols
Posting Yak Master

232 Posts

Posted - 2006-10-19 : 10:35:09
Hello Everyone,

How do I change the format of the Date:

2006-06-01 00:00:00.000

to this:

06-01-2006.

I believe this can be done with a Cast.

Am I correct?

TIA


Kurt

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-19 : 10:36:59
use convert(varchar(10), datecol, 110)

or do it in your front end


KH

Go to Top of Page

kdnichols
Posting Yak Master

232 Posts

Posted - 2006-10-19 : 10:41:11
Hello khtan,

Where do I place this in my code?


USE CHEC
SELECT DISTINCT
DAT01.[_@051] AS Branch,
DAT01.[_@550] AS LoanType,
DAT01.[_@040] AS Date,
DAT01.[_@LOAN#] AS LoanNum
FROM DAT01 INNER JOIN [DATE_CONVERSION_TABLE_NEW]
ON DAT01.[_@040] = [_@040]
INNER JOIN [SMT_BRANCHES]
ON DAT01.[_@051] = SMT_BRANCHES.[BranchNbr]
WHERE
DAT01.[_@040] Between '06/01/2006' And '06/30/2006'
AND DAT01.[_@051] = '540'
And DAT01.[_@LOAN#] Like '2%'
And DAT01.[_@550] = '3'
GROUP BY
DAT01.[_@051],
DAT01.[_@550],
DAT01.[_@TP],
DAT01.[_@040],
DAT01.[_@LOAN#]
ORDER BY
DAT01.[_@051]


DAT01.[_@040] Is the date column.

TIA

Kurt
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-19 : 10:43:22
[code]
SELECT DISTINCT
DAT01.[_@051] AS Branch,
DAT01.[_@550] AS LoanType,
convert(varchar(10), DAT01.[_@040], 110) AS Date,
DAT01.[_@LOAN#] AS LoanNum
[/code]


KH

Go to Top of Page

kdnichols
Posting Yak Master

232 Posts

Posted - 2006-10-19 : 10:51:13
Hello khtan,

Thank you very much.

This works beautifully!

Have a great day!



Kurt
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-20 : 10:12:33
quote:
Originally posted by kdnichols

Hello Everyone,

How do I change the format of the Date:

2006-06-01 00:00:00.000

to this:

06-01-2006.

I believe this can be done with a Cast.

Am I correct?

TIA


Kurt


Where do you want to show data?
If you use front end application, do formation there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-10-20 : 10:16:53
And where did you get such lovely column naming conventions?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -