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

Date Manipulation

Status
Not open for further replies.

Deam

Programmer
Oct 10, 2000
68
US
I need to
find out the first day of the previous calender year and
the last day of the previous calender year.

The following code finds out the the last day of the previous calender year.
SELECT convert(varchar,dateadd(dd,-1,'1/1/'+datename(yy,getdate())))

I need help with finding out the first day of the previous calender year
 
Do you want the name of the day? Like Monday?

If so, try this:

DECLARE @curr_date datetime,
@prev_date datetime,
@my_year integer

SET @curr_date = getdate()
SET @my_year = Year(@curr_date)
SET @prev_date = Convert(datetime, '01/01/' + convert(varchar(4), @my_year))

SELECT DateName(weekday,@prev_date)

Thanks,

Tom
 
Opps, I forgot to include the dateadd...

Try this:

DECLARE @curr_date datetime,
@prev_date datetime,
@my_year integer

SET @curr_date = getdate()
SET @my_year = Year(@curr_date)
SET @prev_date = Convert(datetime, '01/01/' + convert(varchar(4), @my_year))
SET @prev_date = DateAdd(yy,-1,@prev_date)

SELECT DateName(weekday,@prev_date)

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top