SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Get number of days within a date range
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

prasantapaul
Starting Member

India
6 Posts

Posted - 03/12/2014 :  08:39:16  Show Profile  Reply with Quote
I have few date ranges in my database table like below.

01-Jan-2014 to 30-Mar-2014
31-Mar-2014 to 31-Mar-2014

Now I have given a date range (say 26-Feb-2014 to 04-Apr-2014) to retrieve the number of days

which exists in my database date range.

Can you please help me out in this regard?

Edited by - prasantapaul on 03/12/2014 08:40:15

Muj9
Starting Member

United Kingdom
49 Posts

Posted - 03/12/2014 :  10:11:41  Show Profile  Reply with Quote
if you can provide more information on your table are date range and number of dates in the same table or different tables and what sort of out put are you expecting give example.
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 03/12/2014 :  10:18:04  Show Profile  Reply with Quote
you might want to take a look at DateDiff function, considering that you've two date fields

e.g.
Declare @date1 datetime,@date2 datetime
set @date1 = '2014-03-01'
set @date2 = '2014-03-12'
select DateDiff (dd,@date1,@date2)

Cheers
MIK
Go to Top of Page

prasantapaul
Starting Member

India
6 Posts

Posted - 03/13/2014 :  05:55:06  Show Profile  Reply with Quote
Hi Mik

Thanks for your response. But this is not correct. Because I want to get the number days from two date ranges.

Thanks
quote:
Originally posted by MIK_2008

you might want to take a look at DateDiff function, considering that you've two date fields

e.g.
Declare @date1 datetime,@date2 datetime
set @date1 = '2014-03-01'
set @date2 = '2014-03-12'
select DateDiff (dd,@date1,@date2)

Cheers
MIK



Thanks & Regards,
P Paul
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 03/13/2014 :  08:24:13  Show Profile  Reply with Quote
I just gave you an example as how you can get number of days when you've two dates .. range is always meant to be a two date points.

Would you mind explaining why this is not correct? What data you have and what is your desired output for that. It would be better if you provide sample data in the form of insert statement so that we can utilize it. e.g. insert into @tableName values (.....)

Cheers
MIK
Go to Top of Page

sqllover
Constraint Violating Yak Guru

India
334 Posts

Posted - 03/13/2014 :  21:02:15  Show Profile  Reply with Quote
What do you mean by two ranges? The MIK solution is correct. the date range means should be two dates.

elaborate your table and column details.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000