473,397 Members | 1,950 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.

Needing help with time query

25
I am working with a linked table from another database; I cannot change the nature of this table. But I do have to query it for set shifts using a user input date. I made a make table query that isolates the data I need but I cannot get it to display the correct times mainly because of the way that the linked table keeps its time/date, here is its format;

MM/DD/YYYY TT:TT:TT AM/PM

I can get it to display correctly for the current date using;

Like Date() & "*" And >#6:00:00 AM# And <#2:30:00 PM#

but it isn't the current date I need, I need it to display the correct times for first shift (6AM-2:30PM) on the records collected yesterday.

Here is the SQL for the make table query;

Expand|Select|Wrap|Line Numbers
  1. SELECT [dbo_PDTRP FKT].[PDOP], [dbo_PDTRP FKT].[PDSTAT], [dbo_PDTRP FKT].[PDDAT], [dbo_PDTRP FKT].[PD TESTS], [dbo_PDTRP FKT].TYPE, [dbo_PDTRP FKT].PDVEN, [dbo_PDTRP FKT].[PDFP] INTO Datequeryauto
  2. FROM [dbo_PDTRP FKT]
  3. GROUP BY [dbo_PDTRP FKT].[PDOP], [dbo_PDTRP FKT].[PDSTAT], [dbo_PDTRP FKT].[PDDAT], [dbo_PDTRP FKT].[PD TESTS], [dbo_PDTRP FKT].TYPE, [dbo_PDTRP FKT].PDVEN, [dbo_PDTRP FKT].[PDFP]
  4. HAVING ((([dbo_PDTRP FKT].[PDDAT]) Like [enter date] & "*"));
Jan 4 '07 #1
8 1805
guest
25
I guess my question is unclear?
Jan 4 '07 #2
NeoPa
32,556 Expert Mod 16PB
I don't know yet Guest, I've only just got around to looking at it.
Life... you understand.
Jan 4 '07 #3
NeoPa
32,556 Expert Mod 16PB
Firstly, your query is (roughly) equivalent to :
Expand|Select|Wrap|Line Numbers
  1. SELECT [PDOP], [PDSTAT], [PDDAT], [PD TESTS], [TYPE], [PDVEN], [PDFP]
  2. INTO DateQueryAuto
  3. FROM [dbo_PDTRP FKT]
  4. WHERE ([PDDAT] Like [Enter Date] & "*");
And I'm guessing this is what you really want.
However, if you want to select records dependent simply on the date part (no times required - and assuming the field is a Date/Time field), then you need something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT [PDOP], [PDSTAT], [PDDAT], [PD TESTS], [TYPE], [PDVEN], [PDFP]
  2. INTO DateQueryAuto
  3. FROM [dbo_PDTRP FKT]
  4. WHERE (Int([PDDAT])=[Enter Date]);
Dates can get complicated, especially when you have to deal with literals, but in this case we're lucky as, except for the Int() function call (which strips the time part of a Date/Time field) everything we do is as dates.
FYI In a Date/time field, the date is stored as a whole number of days since 30/12/1899 and the time part is stored as a fraction of a day. Using Int() to lose the fractional part converts any Date/time value to the simple date.
Jan 4 '07 #4
guest
25
I am sorry that I made myself unclear, I do not need to query by date, rather I need the query to isolate data that meets criterion specific to time of day. this is because I need to return records that are shift specific.

The query draws from a table containing all the records from a date. So all the records are from say 1/1/2007. But now that the records from that date are isolated I need to split them again into shifts (and as I said before, the field that I am working with keeps both the time and date within the same record ie. "1/1/2007 3:00:00 PM”). So if I were to use the int() function the return a simple date, I will then be unable to split the day into shift times (sadly there is no 'shift' field -=weep=- )

So, now to try to put it a bit more simple. I need to split a date (not the current date) into specific time-oriented shifts.
Jan 4 '07 #5
NeoPa
32,556 Expert Mod 16PB
Separate out the time by saying [DateField] - Int([DateField]) and compare it to a time literal #09:00:00#.
Jan 5 '07 #6
MMcCarthy
14,534 Expert Mod 8TB
Does this help?

Expand|Select|Wrap|Line Numbers
  1. SELECT [dbo_PDTRP FKT].[PDOP], [dbo_PDTRP FKT].[PDSTAT], 
  2. Format([dbo_PDTRP FKT].[PDDAT].''\#mm/dd/yyyy hh:nn:ss\#'),
  3. [dbo_PDTRP FKT].[PD TESTS], [dbo_PDTRP FKT].TYPE, [dbo_PDTRP FKT].PDVEN, [dbo_PDTRP FKT].[PDFP] INTO Datequeryauto
  4. FROM [dbo_PDTRP FKT]
  5. GROUP BY [dbo_PDTRP FKT].[PDOP], [dbo_PDTRP FKT].[PDSTAT], [dbo_PDTRP FKT].[PDDAT], [dbo_PDTRP FKT].[PD TESTS], [dbo_PDTRP FKT].TYPE, [dbo_PDTRP FKT].PDVEN, [dbo_PDTRP FKT].[PDFP]
  6. HAVING ((([dbo_PDTRP FKT].[PDDAT]) Like [enter date] & "*"));
Also make sure your date format in the new table is set to 'General Date'
Jan 5 '07 #7
Heyhey, i posted this as guest before i had an account here ^^. Now i am a member and VERY impressed, thank you NeoPa, that worked GREAT and i have been able to move onto the next step.
Jan 5 '07 #8
NeoPa
32,556 Expert Mod 16PB
Well that's cool.
I didn't even know you could post a question as a guest :confused:
Glad to hear that solved your problem. Lots of us have had to find our way around these sorts of problems in the past, finding solutions where the basic SQL syntax doesn't seem to provide support. We're happy to share our experience and are pleased when it helps.
Jan 6 '07 #9

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

Similar topics

29
by: pb648174 | last post by:
I have a very long transaction that runs on the same database that other users need to use for existing data. I don't care if they see data from the transaction before it is done and am only using...
3
by: dnl | last post by:
I have a parameter query that I would like to simplify so that I wouldn't need to use wildcards when entering in partial data. The following line is in the criteria field when designing the query:...
4
by: Philip_collins | last post by:
Hi! I have a dynamic query that has a form attached. I want to add up a field with the sum funtion, the field is netkg. Dim rec As Recordset Dim qdf As QueryDef Dim strsql Set db =...
3
by: DR | last post by:
I heard there is some trick to referencing statics in C# CLR stored procedure without having to mark the assembly as unsafe. Does anyone know this? This is usefull as the case of needing a little...
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
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,...
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
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...
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
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.