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). - 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;
seems OK - SELECT
-
Tabel1.Id,
-
Tabel1.ADMIT_DATE,
-
Tabel1.DC_DATE,
-
Tabel1.CULTUREDATE,
-
IIf([CULTUREDATE]>=[ADMIT_DATE] And [CULTUREDATE]<=[DC_DATE],1,Null) AS POS_OTHER,
-
IIf([CULTUREDATE] Between [ADMIT_DATE] And [CULTUREDATE],1,Null) AS POS_OTHER2
-
FROM Tabel1;
shows: - Id ADMIT_DATE DC_DATE CULTUREDATE POS_OTHER POS_OTHER2
-
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 - SELECT
-
Tabel1.Id,
-
Tabel1.ADMIT_DATE,
-
Tabel1.DC_DATE,
-
Tabel1.CULTUREDATE,
-
IIf([CULTUREDATE]>=[ADMIT_DATE] And [CULTUREDATE]<=[DC_DATE],1,Null) AS POS_OTHER,
-
IIf([CULTUREDATE] Between [ADMIT_DATE] And [CULTUREDATE],1,Null) AS POS_OTHER2
-
FROM Tabel1;
shows: - Id ADMIT_DATE DC_DATE CULTUREDATE POS_OTHER POS_OTHER2
-
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)
Strange, but changing the format to 24-hours seems to have worked!
Thanks.
Luuk 1,047
Expert 1GB
When i change my dateformat to: 'mm/dd/yyyy hh:nn AM/PM'
It's still working: - Id ADMIT_DATE DC_DATE CULTUREDATE POS_OTHER POS_OTHER2
-
1 08/23/2005 2:02 PM 11/01/2005 3:31 PM 10/18/2005 8:45 PM 1 1
;-)
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).
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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. ...
|
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...
|
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...
|
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...
|
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...
|
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 ...
|
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...
|
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, ...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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...
|
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...
| |