Skip to main content
Ben Nadel at Scotch On The Rocks (SOTR) 2011 (Edinburgh) with: Kirsty Lansdell and James Allen
Ben Nadel at Scotch On The Rocks (SOTR) 2011 (Edinburgh) with: Kirsty Lansdell ( @kirstylansdell ) James Allen ( @CFJamesAllen )
🎄 Early Access Discount 🎄 Feature FlagsFrom Concept to Cultural Revolution

Adding Numbers To Date/Time Values

By on

Ok ok, last SQL date/time post I swear. But, while testing my last entry idea, I realized you can add numbers to your date/time values. Wicked cool:

	-- Query for yesterday's date.
		getDate() - 1
	) AS yesterday,

	-- Query for tomorrow's date.
		getDate() + 1
	) AS tomorrow

Just note that this leaves in the TIME value as-is.

Want to use code from this post? Check out the license.

Reader Comments


I have tried using date functions. But couldn't find exact.

The thing is if I type the date as such 24-08-2012 the output shd be 21-08-2012.
It shd be applicable for all the dates !!

Note : 3 days 4 hours and 22 minutes shd be included

I need the query for the scenario as its imp for one application.


hello ben,
I need to create one exercise by using the Date function. Please help me.
Jus needed a sample query so tat i can wrk it out


This was the question:

"If the day is (Mon/Wed/Fri) print 'Date is Mon/Wed/Fri' "

create procedure exe
@da_Yl date
select day=case DATEPART(DW,@da_Yl)
when '1'then 'na'
when '2'then 'monday'
when '3'then 'na'
when '4'then 'wednes'
when '5'then 'na'
when '6'then 'fri'
when '7'then 'na'

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel