all groups > sql server mseq > january 2007 >
You're in the

sql server mseq

group:

Date formatting - Really newbie question


Date formatting - Really newbie question Chuck G.
1/29/2007 6:51:00 AM
sql server mseq:
I have a unbelievably stupid problem that I can't figure out. My table is
imported from access and contains a column with data type datetime. I want
to be able to sum the data (which is a door counter for our store) to show
me all of the traffic for the day, then display the date as 1/1/2007 instead
of 1/1/2007 12:00:00 PM. I have tried this... (which is how I interpret the
BOL help on this topic)...

convert(smalldatetime, [Date], 101)

No matter what I put in the style portion of the select statement it has no
impact on my output format. I suppose I could convert this to a varchar and
trim the results but that seems to be overkill (in addition to beiing a poor
solution).

RE: Date formatting - Really newbie question Chuck G.
1/30/2007 1:19:00 PM

Solved this. If anyone else is as inexperienced as I am and has this
problem, you can use the following method to change the output of the
datetime in this method.

Select CONVERT(varchar(20), [Date] as DT

will change this
1/30/2007 10:00:00
to this
1/30/2007

[quoted text, click to view]
Re: Date formatting - Really newbie question Steve Kass
2/25/2007 11:06:56 PM
I don't quite see how that works (20 is too long, and the is only one
parenthesis). To
convert a datetime value to the same date at midnight, this is one solution:

dateadd(day,datediff(day,0,[Date]),0)

-- Steve Kass
-- Drew University
-- http://www.stevekass.com

[quoted text, click to view]
AddThis Social Bookmark Button