473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

query to find days between two dates.

Expand|Select|Wrap|Line Numbers
  1. DECLARE @startDate DATETIME
  2. DECLARE @endDate DATETIME
  3. SET @startDate = '2013-10-23'
  4. SET @endDate = '2013-10-31'
  5. ;WITH dates AS 
  6. (
  7.     SELECT @startdate as Date,DATENAME(Dw,@startdate) As DayName
  8.     UNION ALL
  9.     SELECT DATEADD(d,1,[Date]),DATENAME(Dw,DATEADD(d,1,[Date])) as DayName
  10.     FROM dates 
  11.     WHERE DATE < @enddate
  12. )
  13. SELECT Date,DayName frOM dates
Nov 13 '13 #1
6 10093
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

What is your question?
Nov 13 '13 #2
ma question is.....how to find days between two dates using sql ??
Nov 19 '13 #3
ck9663
2,878 Expert 2GB
Here, read this

Happy Coding!!!


~~ CK
Nov 19 '13 #4
did you got it ? @ck9663
Nov 22 '13 #5
Expand|Select|Wrap|Line Numbers
  1. SELECT DATEDIFF(day,'2013-10-23','2013-10-31') AS DiffDate
Dec 9 '13 #6
Try This:

Expand|Select|Wrap|Line Numbers
  1. DECLARE @startDate DATETIME 
  2. DECLARE @endDate DATETIME 
  3. SET @startDate = DATEADD(day,-8,@enddate)
  4. SET @endDate = @FromDate
  5. ;WITH dates AS  
  6.     SELECT @startdate  
  7.     UNION ALL 
  8.     SELECT DATEADD(d,1,[Date]) 
  9.     FROM dates  
  10.     WHERE DATE < @enddate 
  11. SELECT Date,DayName frOM dates
Dec 9 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Phantom_guitarist | last post by:
I am trying to write a query (in PHP) which selects from a database all of the items which are in the future. My query is as follows SELECT * FROM news WHERE ((news.date)>$today ORDER BY date ...
3
by: Lapchien | last post by:
done homework on Usenet and still stuck... I have a parameter query that asks the user to input the 'slip reference' based on the accounting period. This has now changed slightly so that the...
3
by: Deano | last post by:
Ta for looking. I am setting this SQL to the recordsource of a report but it's complaining about a syntax error. "SELECT tblemp.Surname, tblemp.Forename, tblAbsence.AbsenceDate,...
13
newnewbie
by: newnewbie | last post by:
I have an Access database that I upload a data extract intoto daily. I want to create a query that will give me a list of dates that no data can be found for. E.g. there are no records created on the...
5
by: JD | last post by:
Example Give me all the dates between 02/02/07 and 05/02/07 ? In Europe the answer must be 4 dates : 02/02/07 ; 03/02/07 ; 04/02/07 ; 05/02/07. JD.
1
by: vkong85 | last post by:
I am trying to write a query that will only display records between today's date and 30 days. I've tried several different ways but nothing seems to work. Currently in the criteria of the date...
3
by: bobdydd | last post by:
Hi Everybody I am trying to be able to filter records by whether the date field which is called "RiskDate" in the recordset, is either: 1. Is Null 2. Not Null The parameter in the query...
2
by: vjw | last post by:
Hi, is there a way to query all days of a given month? for ex: there should be 31 records for January..28 for february like that..
1
by: DAHMB | last post by:
I have a report based on a query that has two dates that I need information filtered on, and then return the information in the same report. I have a date a case was opened and a date a case was...
2
by: khaing | last post by:
How can I get the dates between two dates depending on days? For example, if I give the start date '10-05-2010' and end date '24-05-2010' and days are Mon, Wed, Fri , the result should be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.