473,396 Members | 1,864 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,396 software developers and data experts.

SQL date compare problem

I'm trying to check a few fields in my SQL query to ensure that they fall
between a range (namly that today's date is greater than one field and less
than another field.)

This is what I have:

=========================================
dim strCurrentDate as String =
microsoft.VisualBasic.DateAndTime.Today().ToString ("mm/dd/yyyy")

Dim strChk As String

strChk = "SELECT ALL seminarID, seminarTitle, seminarAttendanceLimit,
seminarEventDate, seminarTimes FROM LottsaA_dminDBA.webSeminars WHERE
(seminarPostDate <=" & strCurrentDate & ") AND (seminarPullDate > " &
strCurrentDate & ")"
=========================================

It's not working. If I remove the WHERE statement alltogether, I can grab
the records, but with it there, it's not finding anything. I'm wondering if
the issue is that I'm passing the currentdate as a string...instead of an
actual date. In SQL, they are set as 'datetime' fields.

-Darrel
Nov 18 '05 #1
5 2282
append quotes for date fields in the query..

strChk = "SELECT ALL seminarID, seminarTitle, seminarAttendanceLimit,
seminarEventDate, seminarTimes FROM LottsaA_dminDBA.webSeminars WHERE
(seminarPostDate <='" & strCurrentDate & "') AND (seminarPullDate > '" &
strCurrentDate & "')"

Av.
http://dotnetjunkies.com/WebLog/avnrao
http://www28.brinkster.com/avdotnet

"Darrel" <no*****@nospam.com> wrote in message
news:eV**************@TK2MSFTNGP10.phx.gbl...
I'm trying to check a few fields in my SQL query to ensure that they fall
between a range (namly that today's date is greater than one field and less than another field.)

This is what I have:

=========================================
dim strCurrentDate as String =
microsoft.VisualBasic.DateAndTime.Today().ToString ("mm/dd/yyyy")

Dim strChk As String

strChk = "SELECT ALL seminarID, seminarTitle, seminarAttendanceLimit,
seminarEventDate, seminarTimes FROM LottsaA_dminDBA.webSeminars WHERE
(seminarPostDate <=" & strCurrentDate & ") AND (seminarPullDate > " &
strCurrentDate & ")"
=========================================

It's not working. If I remove the WHERE statement alltogether, I can grab
the records, but with it there, it's not finding anything. I'm wondering if the issue is that I'm passing the currentdate as a string...instead of an
actual date. In SQL, they are set as 'datetime' fields.

-Darrel

Nov 18 '05 #2
> append quotes for date fields in the query..

Hmm...doing that returns this error:

Error accessing Database.
The conversion of a char data type to a datetime data type resulted in an
out-of-range datetime value.

-Darrel
Nov 18 '05 #3
If you want to check today date why don't you use getdate() of sql server?
strChk = "SELECT ALL seminarID, seminarTitle, seminarAttendanceLimit,
seminarEventDate, seminarTimes FROM LottsaA_dminDBA.webSeminars WHERE
(seminarPostDate <=getdate()) AND (seminarPullDate > getdate())"
"Darrel" <no*****@nospam.com> wrote in message news:<eV**************@TK2MSFTNGP10.phx.gbl>...
I'm trying to check a few fields in my SQL query to ensure that they fall
between a range (namly that today's date is greater than one field and less
than another field.)

This is what I have:

=========================================
dim strCurrentDate as String =
microsoft.VisualBasic.DateAndTime.Today().ToString ("mm/dd/yyyy")

Dim strChk As String

strChk = "SELECT ALL seminarID, seminarTitle, seminarAttendanceLimit,
seminarEventDate, seminarTimes FROM LottsaA_dminDBA.webSeminars WHERE
(seminarPostDate <=" & strCurrentDate & ") AND (seminarPullDate > " &
strCurrentDate & ")"
=========================================

It's not working. If I remove the WHERE statement alltogether, I can grab
the records, but with it there, it's not finding anything. I'm wondering if
the issue is that I'm passing the currentdate as a string...instead of an
actual date. In SQL, they are set as 'datetime' fields.

-Darrel

Nov 18 '05 #4
> If you want to check today date why don't you use getdate() of sql server?

Becuase I didn't know it existed. Hence me asking the question. ;o)
strChk = "SELECT ALL seminarID, seminarTitle, seminarAttendanceLimit,
seminarEventDate, seminarTimes FROM LottsaA_dminDBA.webSeminars WHERE
(seminarPostDate <=getdate()) AND (seminarPullDate > getdate())"


Ah...this looks exactly the solution. Thanks! I saw references to getdate()
but didn't make the connection that this is a SQL command that you put
directly in the query.

-Darrel
Nov 18 '05 #5
:-) OK

"darrel" <no*****@hotmail.com> wrote in message news:<#n**************@TK2MSFTNGP11.phx.gbl>...
If you want to check today date why don't you use getdate() of sql server?


Becuase I didn't know it existed. Hence me asking the question. ;o)
strChk = "SELECT ALL seminarID, seminarTitle, seminarAttendanceLimit,
seminarEventDate, seminarTimes FROM LottsaA_dminDBA.webSeminars WHERE
(seminarPostDate <=getdate()) AND (seminarPullDate > getdate())"


Ah...this looks exactly the solution. Thanks! I saw references to getdate()
but didn't make the connection that this is a SQL command that you put
directly in the query.

-Darrel

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
1
by: Amal Ismail | last post by:
hello i'm inquiring about something .. hope to find help here i'm using ASP.NET Mobile web application using c# And i'm facing a problem , i use SQL server Database I've table inside it a...
4
by: Stephen | last post by:
Is there any way of using a compare validator to compare a textbox to see if the date is greater than or equal to todays date. I want to set the ValueToCompare property to now(). It doesn't seem...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
4
by: blini | last post by:
Helo.... How I can convert string "26/03/2006 15:51" for a date? I need to convert and to compare if "09/06/2006 14:20" is lesser or equal that the current date. Everything in Javascript.
1
by: Budd | last post by:
Hi everyone i got a problem on date, it is... 1, i get the date from calendar component 2, compare today and selected date is equal (compare method) 3 count the number of day between this...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
3
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn...
2
by: deepikashalini | last post by:
hi, Im storing Issue date in database. Issuedate stored as varchar. and then compare to Passing string date('03/06/2008') what is query to compare storing varchar date to passing string...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.