473,397 Members | 2,077 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,397 software developers and data experts.

MS Acess Date in SQL

Can someone please explain this to me.

When I run the following query in MS Access, it doesn't return
anything.

SELECT tbl_vdc.vcd_id, tbl_vdc.vcd_count, tbl_vdc.batch_day
FROM tbl_vdc
WHERE tbl_vdc.batch_day = #9/24/2004#;

But if I run the following query, it returns one record for
09/24/2004.

SELECT tbl_vdc.vcd_id, tbl_vdc.vcd_count, tbl_vdc.batch_day
FROM tbl_vdc
WHERE tbl_vdc.batch_day Between #9/24/2004# And #9/25/2004#;

Even though there is a record for 09/25/2004, it doesn't return it
with the above statement. To get records for the 25th, my date range
has to go pass the date of the 25th.

Is there anything wrong with the 1st query? And how come the second
query doesn't include records for the 25th?

Thanks.

Gabsaga
Nov 13 '05 #1
3 3105
Taji wrote:
Can someone please explain this to me.

When I run the following query in MS Access, it doesn't return
anything.

SELECT tbl_vdc.vcd_id, tbl_vdc.vcd_count, tbl_vdc.batch_day
FROM tbl_vdc
WHERE tbl_vdc.batch_day = #9/24/2004#;

But if I run the following query, it returns one record for
09/24/2004.

SELECT tbl_vdc.vcd_id, tbl_vdc.vcd_count, tbl_vdc.batch_day
FROM tbl_vdc
WHERE tbl_vdc.batch_day Between #9/24/2004# And #9/25/2004#;

Even though there is a record for 09/25/2004, it doesn't return it
with the above statement. To get records for the 25th, my date range
has to go pass the date of the 25th.

Is there anything wrong with the 1st query? And how come the second
query doesn't include records for the 25th?


Your field (batch_day) likely includes both date and time data.
Actually ALL DateTime fields in Access include both a date and a time.
It's just that when you don't specify a time, midnight is assumed.

So...when you apply criteria to a DateTime field and only supply the
date as the criteria you are actually applying a criteria for records on
that date that also have midnight as the time.

Use of the BETWEEN statement is a good way to deal with this. When
doing BETWEEN statements it is a common practice to add a day to the
"end date" value so that you actually get the records that occurred on
the previous day.

On small tables you can also do something like...

WHERE DateValue(batch_day) = #9/24/2004#

That will strip the time off of the value being tested, however whenever
you test against an expression you lose the capability for Access to use
any index you might have on the field so it is not as efficient.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2
ga**********@hotmail.com (Taji) wrote in message news:<15**************************@posting.google. com>...
SELECT tbl_vdc.vcd_id, tbl_vdc.vcd_count, tbl_vdc.batch_day
FROM tbl_vdc
WHERE tbl_vdc.batch_day Between #9/24/2004# And #9/25/2004#;


A Date type field contains a Date AND a Time. Comparing that field to just a
Date will not yield a match since the time portion may not match, i.e.,
#10/4/2004 12:01# does not equal #10/4/2004 12:02#.

Try using the DateValue() function to pull just the Date:

SELECT tbl_vdc.vcd_id, tbl_vdc.vcd_count, tbl_vdc.batch_day
FROM tbl_vdc
WHERE DateValue(tbl_vdc.batch_day) = #9/24/2004#;
Nov 13 '05 #3
mi****@execpc.com (almish) wrote in message news:<95**************************@posting.google. com>...
ga**********@hotmail.com (Taji) wrote in message news:<15**************************@posting.google. com>...
SELECT tbl_vdc.vcd_id, tbl_vdc.vcd_count, tbl_vdc.batch_day
FROM tbl_vdc
WHERE tbl_vdc.batch_day Between #9/24/2004# And #9/25/2004#;


A Date type field contains a Date AND a Time. Comparing that field to just a
Date will not yield a match since the time portion may not match, i.e.,
#10/4/2004 12:01# does not equal #10/4/2004 12:02#.

Try using the DateValue() function to pull just the Date:

SELECT tbl_vdc.vcd_id, tbl_vdc.vcd_count, tbl_vdc.batch_day
FROM tbl_vdc
WHERE DateValue(tbl_vdc.batch_day) = #9/24/2004#;


Thanks guys for all your help. That explained it all and the DateValue
function did the trick.
Nov 13 '05 #4

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

Similar topics

0
by: minhadd | last post by:
Hello Would Anyone help me ?? I want insert into Microsoft Acess visitor's IP by ASP. But It is not working ...
8
by: josecruz | last post by:
I am running a report and using date ranges. I will like that when I run the report to see printed those date ranges that I enter on the parameter. Could someone assist me or direct me in the proper...
2
by: sonasiva | last post by:
hai Iam creating my own website using ASP and MS ACESS ,iam new to ASP and SQL Please help me to write a query to finish my project. i have datas as follows in my database sno name ...
4
by: IsdWeb | last post by:
Hello, I am a newbie to coding and need some help. I am trying to figure out why the following code is not producing the correct Julian date. Any suggestions? Also, I am trying to understand...
0
by: sreekandan | last post by:
Hi everybody, Im doing project in VB6 and Ms Access as backend. In that, While i am running the project, if the person signIn then the System Time store into the database table.Once if the person...
2
by: vaddi | last post by:
hello, I have query , which has got 2 outer joins. The query is: SELECT A.Project_ID, A.Title, A.comm1 AS Comments, A.Partner AS PM, A.Staff_Assigned AS TL, A.Contact_Name AS FL, A.MD,...
0
by: mykhan | last post by:
I have been using access database with asp.net pages. I just realized a problem with date saving in access table. I didnt give any specific format for the date when saved in tables, because I wanted...
1
by: qwer | last post by:
hi im actually doing on a SMS application using Visual Basic.Net whereby the objective is to allow the user to send a SMS to the visual basic programme and i should decode out the hp no, car plate,...
1
by: lokeshreddy16 | last post by:
'this is my code plz guys help how to save data from vb 2005 and other this that i am able to view the data from acess but i am not able save to acess i dont whether my code for save is correct of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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,...
0
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...

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.