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

Date field in DB

I am trying to compare the current date() with the date in an access db to
pull out only records where the date is later than the todays date (so
records where the date hasn't passed)

Then I do this:-

strSQL = "select * from tblEvents where enddate > " & date() & " order by
startdate"

it pulls me out every record even ones with the dat in the past.

When I response.write the date() and objRS("enddate") to the screen the
dates are correct/same format and the date() is older than the
objRS("enddate") . So why is it pulling it out of the DB.

I know a way to do it would be to pull all records out and do an if
statement, but if I have, for example, 100 events 98 of which were expired,
then it would be a waste of processing time to do the if and loop when I
could pull them out from the DB from the start.

Any ideas how I can et round this please?

Cheers for anyones help.

Stu
Jul 19 '05 #1
6 2444
If you did a:

response.write strSQL
response.End

You'd probably get:

select * from tblEvents where enddate > 7/31/2003 order by startdate

So, what does that say? It says:

Select * from tblEvents where EndDate is greater than (7 divided by 31
divided by 2003).
(At least that's what I believe is happening.)

In Access, you need to delimit dates with the # sign, I believe. So, try:

strSQL = "select * from tblEvents where enddate > #" & date() & "# order by
startdate"

Alternatively, you can use DATE() in your SQL query itself:

Ray at work
"Stuart Palmer" <tr**********@youcant.com> wrote in message
news:bg**********@sp15at20.hursley.ibm.com...
I am trying to compare the current date() with the date in an access db to
pull out only records where the date is later than the todays date (so
records where the date hasn't passed)

Then I do this:-

strSQL = "select * from tblEvents where enddate > " & date() & " order by
startdate"

it pulls me out every record even ones with the dat in the past.

Jul 19 '05 #2
Good observation Ray. I don't think I would have caught that... :o)

-Andrew
If you did a:

response.write strSQL
response.End

You'd probably get:

select * from tblEvents where enddate > 7/31/2003 >order by startdate

So, what does that say? It says:

Select * from tblEvents where EndDate is greater >than (7 divided by 31
divided by 2003).
(At least that's what I believe is happening.)

In Access, you need to delimit dates with the # >sign, I believe. So, try:
strSQL = "select * from tblEvents where enddate > >#" & date() & "# order bystartdate"

Alternatively, you can use DATE() in your SQL >query itself:

Ray at work


* * * Sent via DevBuilder http://www.devbuilder.org * * *
Developer Resources for High End Developers.
Jul 19 '05 #3
Getting screwed by something one time is to enough to make you remember. ;]

Ray at work

"Andrew J Durstewitz" <ad******@devbuilder.org> wrote in message
news:3f*********************@news.frii.net...
Good observation Ray. I don't think I would have caught that... :o)

-Andrew
If you did a:

response.write strSQL
response.End

You'd probably get:

select * from tblEvents where enddate > 7/31/2003 >order by startdate

So, what does that say? It says:

Select * from tblEvents where EndDate is greater >than (7 divided by 31
divided by 2003).
(At least that's what I believe is happening.)

Jul 19 '05 #4
In addition to Ray's suggestion, you can do this, instead:
strSQL = "select * from tblEvents where enddate > date()" & _
" order by startdate"

JetSQL can a use the VBA date() function "internally". There is no need to
pass the current date to the query.

HTH,
Bob Barrows

PS. You should avoid "Select *" (selstar for short) in production code since
it virtually guarantees that you will be pulling unnecessary data across the
wire. Explicitly list the desired fields in your select statement.

Stuart Palmer wrote:
I am trying to compare the current date() with the date in an access
db to pull out only records where the date is later than the todays
date (so records where the date hasn't passed)

Then I do this:-

strSQL = "select * from tblEvents where enddate > " & date() & "
order by startdate"

it pulls me out every record even ones with the dat in the past.

When I response.write the date() and objRS("enddate") to the screen
the dates are correct/same format and the date() is older than the
objRS("enddate") . So why is it pulling it out of the DB.

I know a way to do it would be to pull all records out and do an if
statement, but if I have, for example, 100 events 98 of which were
expired, then it would be a waste of processing time to do the if and
loop when I could pull them out from the DB from the start.

Any ideas how I can et round this please?

Cheers for anyones help.

Stu


Jul 19 '05 #5
Hey, that was my second suggestion, man! :P

Ray at work

"Bob Barrows" <re*******@yahoo.com> wrote in message
news:Ob**************@TK2MSFTNGP12.phx.gbl...
In addition to Ray's suggestion, you can do this, instead:
strSQL = "select * from tblEvents where enddate > date()" & _
" order by startdate"

JetSQL can a use the VBA date() function "internally". There is no need to
pass the current date to the query.

Jul 19 '05 #6
Oh yeah!! Come on - reread your message: that was easy to miss wasn't it?
:-)

Ray at <%=sLocation%> wrote:
Hey, that was my second suggestion, man! :P

Ray at work

"Bob Barrows" <re*******@yahoo.com> wrote in message
news:Ob**************@TK2MSFTNGP12.phx.gbl...
In addition to Ray's suggestion, you can do this, instead:
strSQL = "select * from tblEvents where enddate > date()" & _
" order by startdate"

JetSQL can a use the VBA date() function "internally". There is no
need to pass the current date to the query.


Jul 19 '05 #7

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

Similar topics

16
by: jason | last post by:
I'm tearing out my hair here: ACCESS 2000: When I attempt to overwrite a date in my date field with a new user selected valid date eg: 05/23/99 my date field changes to the TIME I updated the...
7
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time =...
3
by: BlackFireNova | last post by:
This concerns an Access 2002 (XP) database. There are two fields, "Notes" (Memo Field) and "Notes Update" on a form (among others) which I am concerned with here. Problem: I need to be able...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
3
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to same date. SELECT IM.Area, IM.Location,...
1
by: EV | last post by:
We have a personnel database that we want to set up...For time off we will have a start date field and an end date field as well as a field for the number of hours. We need to determine how many...
1
by: Monica Roman | last post by:
Hello, help please. I have a little macro that copies the date from a date/time field to a memo field, BUT instead of going to the memo field it finds the first date/time field and tries to copy...
1
by: Graham Feeley | last post by:
I have a date field named rcdate it is a general date eg: 12/08/2006 3:30:00 PM 12/08/2006 3:00:00 PM I used to update another empty field named rdate with the with using in a update query "...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
7
by: sheri | last post by:
I have a field called date, the date is in the field like this 70925 (which means Sept. 25, 2007). I have another field called day, it is a text field. How do I write a query to populate the day...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.