[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL Date with minimum time and like date with maximum time

Posted on 2013-06-19
4
Medium Priority
?
294 Views
Last Modified: 2013-06-19
If I enter dates into a parameter and both dates are the same how can I make one of the dates the minimum value for that date so 00:00 and the end date 23:59.

so
BETWEEN @StartDate AND @EndDate

I know its likely to be simple but I just cant figure it.

Regards
S
0
Comment
Question by:SimonJohnG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
PortletPaul earned 2000 total points
ID: 39259503
don't use between

use this instead

[field] >= @StartDate AND [field] < dateadd(day,1,@EndDate)

so, if the parameters are both '2013-06-01'

this equates to:
[field] >= '2013-06-01' AND [field] < dateadd(day,1,'2013-06-01') -- i.e. '2013-06-02'

If the parameters are '2013-06-01' & '2013-06-30'

this equates to:
[field] >= '2013-06-01' AND [field] < dateadd(day,1,'2013-06-30') -- i.e. '2013-07-01'

avoiding "between" is the solution.
for more on this topic please see: "Beware of Between"
0
 

Author Comment

by:SimonJohnG
ID: 39259572
Thank you for your help, works great.

Regards
Simon
0
 

Author Closing Comment

by:SimonJohnG
ID: 39259580
Fantastic reponse time and clear and precise explaination. Thank you
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39261034
and thank you! Quick closures is very much appreciated too.

Do take be cautious of using 'between' when filtering by date ranges, the >= with < construct is usually a more reliable method (You just need to get used to the idea that the higher date is 'the next day'). Do read that article if you need more.

Cheers, Paul
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question