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

Between dates query not working

lilp32
43
I cannot figure out what I am doing wrong. I am trying to write a query to put a "1" UNDER "POS_OTHER" when a culture (CULTUREDATE) is between [ADMIT_DATE] AND [DC_DATE]. All 3 date fields are formatted as vb general date/time, but there are many instances being missed (see screenshot).
Expand|Select|Wrap|Line Numbers
  1. SELECT Neg_on_admit_dates_formatted.REPID, Neg_on_admit_dates_formatted.ADMIT_DATE, Neg_on_admit_dates_formatted.DC_DATE, Neg_on_admit_dates_formatted.CULTUREDATE, IIf([CULTUREDATE] Between [ADMIT_DATE] And [DC_DATE],1,Null) AS POS_OTHER FROM Neg_on_admit_dates_formatted;

Attached Images
File Type: jpg access_dates.jpg (120.2 KB, 478 views)
Apr 11 '14 #1

✓ answered by Luuk

seems OK
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.    Tabel1.Id, 
  3.    Tabel1.ADMIT_DATE, 
  4.    Tabel1.DC_DATE, 
  5.    Tabel1.CULTUREDATE, 
  6.    IIf([CULTUREDATE]>=[ADMIT_DATE] And [CULTUREDATE]<=[DC_DATE],1,Null) AS POS_OTHER, 
  7.    IIf([CULTUREDATE] Between [ADMIT_DATE] And [CULTUREDATE],1,Null) AS POS_OTHER2
  8. FROM Tabel1;
shows:
Expand|Select|Wrap|Line Numbers
  1. Id    ADMIT_DATE    DC_DATE    CULTUREDATE    POS_OTHER    POS_OTHER2
  2. 1    23-8-2005 14:02:00    1-11-2005 15:31:00    18-10-2005 20:45:01    1    1
(my date-format is DD-MM-YYYY, and time in 24-hours)

4 1678
Luuk
1,047 Expert 1GB
seems OK
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.    Tabel1.Id, 
  3.    Tabel1.ADMIT_DATE, 
  4.    Tabel1.DC_DATE, 
  5.    Tabel1.CULTUREDATE, 
  6.    IIf([CULTUREDATE]>=[ADMIT_DATE] And [CULTUREDATE]<=[DC_DATE],1,Null) AS POS_OTHER, 
  7.    IIf([CULTUREDATE] Between [ADMIT_DATE] And [CULTUREDATE],1,Null) AS POS_OTHER2
  8. FROM Tabel1;
shows:
Expand|Select|Wrap|Line Numbers
  1. Id    ADMIT_DATE    DC_DATE    CULTUREDATE    POS_OTHER    POS_OTHER2
  2. 1    23-8-2005 14:02:00    1-11-2005 15:31:00    18-10-2005 20:45:01    1    1
(my date-format is DD-MM-YYYY, and time in 24-hours)
Apr 11 '14 #2
lilp32
43
Strange, but changing the format to 24-hours seems to have worked!

Thanks.
Apr 11 '14 #3
Luuk
1,047 Expert 1GB
When i change my dateformat to: 'mm/dd/yyyy hh:nn AM/PM'
It's still working:

Expand|Select|Wrap|Line Numbers
  1. Id    ADMIT_DATE    DC_DATE    CULTUREDATE    POS_OTHER    POS_OTHER2
  2. 1    08/23/2005 2:02 PM    11/01/2005 3:31 PM    10/18/2005 8:45 PM    1    1
;-)
Apr 11 '14 #4
NeoPa
32,556 Expert Mod 16PB
I'm only guessing here, but from the name of the input source, the 'Dates' we're talking about are not really dates at all, but formatted date strings instead.

See Literal DateTimes and Their Delimiters (#) for some background that may help you understand what the difference is and why it's so important when working with dates in a database project.

I can confirm that, had the fields been actual date (Date/Time) fields then your original SQL would have worked perfectly without regard to the format of the values when shown.

NB. It always makes best sense to deal with the native date data when trying to work with dates. Formatted string values should only ever be used for interfacing with the human element. So, display formatted, but work in native (Date/Time).
Apr 13 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: David | last post by:
I'm new to DB2 and I need to write a query that will allow me to find specific dates instead of me having a date range asked for, I want it to be calculated. I've done this in Access by coding...
3
by: MMFBprez | last post by:
I am trying to compute storage charges by getting the number of months between dates and multiplying it by a rate. I cannot get a correct number of months if the date is greater than a year ago. ...
1
by: John | last post by:
Hi Folks, I currently have a which I run on a databse of club member which gives me a total amount paid by each member in each calendar year...03,04,05 ect. The problem I have is that I need to...
2
by: Carl | last post by:
Hi, I have a query that produces an output similar to the sample shown below. These records are based on certain criteria and a date range selected from a form. I need to create some kind of...
1
by: pitfour.ferguson | last post by:
My dbase has the start date and end date of each visit. How can I ask Access to list the day of the week of the start (easy), end (easy) and, more importantly, the dates of the visit itself - ie...
15
by: @sh | last post by:
For some reason guys my SQL string isn't working and I'm probably doing something stupid? SELECT * FROM sol_session SELECT * FROM SOL_Session WHERE DateGiven...
1
by: santiago | last post by:
Hello. I'm having troubles with a query that (should) return all the records between two dates. The date field is a datetime type. The db is SQL Server 2000. When I try this SELECT ...
4
AccessQuestion
by: AccessQuestion | last post by:
I am at my wits end. Why is this not simple? So I am trying to query records that fall between two dates, but the ending date is not showing up. So, if I want to see if there is data for today my...
2
by: luvkush | last post by:
i want to retrieve the records selected between from_dt and to_dt and also the records of the selected date should be retrieved... SELECT ChallanDtl.chalID, ChallanDtl.chalTo, ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.