473,578 Members | 3,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2450
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**********@y oucant.com> wrote in message
news:bg******** **@sp15at20.hur sley.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.wri te 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"

Alternativel y, 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******@devbu ilder.org> wrote in message
news:3f******** *************@n ews.frii.net...
Good observation Ray. I don't think I would have caught that... :o)

-Andrew
If you did a:

response.wri te 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*******@yaho o.com> wrote in message
news:Ob******** ******@TK2MSFTN GP12.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*******@yaho o.com> wrote in message
news:Ob******** ******@TK2MSFTN GP12.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
2200
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 field and does not display my desired date: 05/23/99 Instead it reads: 12:12:03 AM I am going nuts - even considering converting the field to...
7
682729
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 = '01-SEP-02' I'm getting no results. The date_and_time field is formatted like this: 2002-SEP-02 00:01:04
3
12958
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 to tell when people have added notes to a record. (this database contains 6000+ records) I want to set it up so that "Notes Update" is updated to...
10
2966
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 1jan2003. How do I remove the dates , 2jan2003 til 31jan2003 without removing them from the table, from the Query? (Because I want to use the data for...
3
2561
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, IT.itemid, IT.date,
1
1652
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 people (via query) will be off for any given day (date) - for example: Roy is off 8/9/04 (start date field) - 8/12/04 (end date field) Bob is off...
1
2037
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 there. My first thought is to change the date to text but how? Thanks!!! Monica
1
1835
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 " Left(Ratings!RCDate,10)" This now does not work for some reason gives me the error "undefined function in left function"
6
12536
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 calendar control to allow my users to enter a date but I need them to enter a time as well. It doesn't look like the calendar control will allow...
7
10181
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 field from the date field? Thanks for your help.
0
7847
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7778
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8290
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8148
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1389
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.