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
 T-SQL Date Format

Author  Topic 

forefj
Starting Member

10 Posts

Posted - 2012-08-10 : 14:42:55
I have a table where I select customer purchase activity and it will display the date of purchase (along with the time) in ColumnA, in this format:
2012-08-06 10:06:42.223
YYYY-MM-DD HH:MM:SS

I want to display the date only, so I added a LEFT function like so:
LEFT(ColumnA,11)

This will get rid of the time but now the date is displayed I will get:
Aug 06 2012


I want to display it in numeric format but as MM/DD/YYYY so it will look like:
08/06/2012
MM/YY/YYYY
Any ideas how I can do this in T-SQL? Thanks for any assistance.

forefj
Starting Member

10 Posts

Posted - 2012-08-10 : 14:58:43
Found the answer:
CONVERT(VARCHAR(10),ColumnA,101) as [Join Date],
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-10 : 15:23:06
please dont change original datatype of field for stripping off time

use a logic like

DATEADD(dd,DATEDIFF(dd,0,ColumnA),0)


see

http://visakhm.blogspot.com/2012/07/generate-datetime-values-from-integers.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -