Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

What is a good way to compare the month portion of a date when using an SQL query?

Posted on 2006-07-11
4
Medium Priority
?
201 Views
Last Modified: 2010-04-23
I have a database with a field containing dates in the format yyyy/mm/dd. I get the beginning and ending months from the user with 2 combo boxes. So let's say the user wants only the samples between SEP and OCT.  What is the correct SQL syntax to get this?  I'm looking for the '....' part of the Select statement below. I am using Access and VB.Net 1.1

Thank you in advance.


cboFMonth.Text = "SEP"
cboLMonth.Text = "NOV"
Dim strSQL as String =  "SELECT DateReceived WHERE DateReceived...."
0
Comment
Question by:IT_Steve
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
snow_moon earned 2000 total points
ID: 17086252
SELECT DateReceived WHERE datepart(month,DateReceived) between 9 and 10
0
 
LVL 8

Expert Comment

by:doobdave
ID: 17090573
Hi there,
the above is correct and works, but you can also use the MONTH function as follows:

SELECT DateReceived WHERE MONTH(DateReceveived) = 1

which is a little more succinct.

I don't believe there's any difference in performance between the two so I guess it's just personal preference.

Best Regards,

David
0
 

Author Comment

by:IT_Steve
ID: 17091023
Thank you Snow Moon for the solution. I just had to change datepart(month,DateReceived)  to datepart("m",DateReceived)  and it performed exactly as I wanted. I did not see DoobDave's solution until after I accepted Snow Moons but can also see that would work too. Thank you both for your assistance.
0
 
LVL 8

Expert Comment

by:doobdave
ID: 17091797
Hi Steve,

no problem, glad you go your solution!

Best Regards,

David
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month20 days, 23 hours left to enroll

810 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