RE: datename

RE: datename

 

  

This will do what you need. For a better understanding, look up the dateadd
and convert topics in Books Online (BOL).

declare @yesterday datetime, @today datetime

select @today = getdate()
select @yesterday = convert(char(10),dateadd(dd,-1,@today),120)

select @today, @yesterday

Hope this helps

Tom

-----Original Message-----
From: Bowman, Steve [mailto:[Email Address Removed] Thursday, July 31, 2003 1:06 PM
To: LazyDBA.com Discussion
Subject: datename


Gurus,
When I use the "datename" function to extract the day of year from a
datestamp is there a way to get the date back out of the output?

example:

declare @date int,
@date2 int

set @date = (SELECT DATENAME(dy, getdate()))

set @date2 = @date -1

select @date2

I need to create a date stamp ( in yyyy-mm-dd 00:00:00.000 ) format from
this output.

Does anyone know how to accomplish this?

TIA,

-steveb
MS Sql Server LazyDBA home page