PC Review


Reply
Thread Tools Rate Thread

Date select query

 
 
MikeR
Guest
Posts: n/a
 
      29th Oct 2008
I have a need to select records that have a date/time field, but I am only supplied
with a date. Is there something more elegant than "Select Mgr, LDate, CaseNum from
Log Where LDate BETWEEN #01-01-2008 00:00:00# AND #01-01-2008 11:59:59#"

Thanks,
Mike
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      29th Oct 2008
On Wed, 29 Oct 2008 16:55:21 -0400, MikeR <(E-Mail Removed)> wrote:

>I have a need to select records that have a date/time field, but I am only supplied
>with a date. Is there something more elegant than "Select Mgr, LDate, CaseNum from
>Log Where LDate BETWEEN #01-01-2008 00:00:00# AND #01-01-2008 11:59:59#"
>
>Thanks,
>Mike


I'd use a Form with an unbound textbox txtDate, and a criterion like

>= CDate([Forms]![YourForm]![txtDate] AND < DateAdd("d", 1, CDate([Forms]![YourForm]![txtDate]))


--

John W. Vinson [MVP]
 
Reply With Quote
 
MikeR
Guest
Posts: n/a
 
      29th Oct 2008
John W. Vinson wrote:
> On Wed, 29 Oct 2008 16:55:21 -0400, MikeR <(E-Mail Removed)> wrote:
>
>> I have a need to select records that have a date/time field, but I am only supplied
>> with a date. Is there something more elegant than "Select Mgr, LDate, CaseNum from
>> Log Where LDate BETWEEN #01-01-2008 00:00:00# AND #01-01-2008 11:59:59#"
>>
>> Thanks,
>> Mike

>
> I'd use a Form with an unbound textbox txtDate, and a criterion like
>
>> = CDate([Forms]![YourForm]![txtDate] AND < DateAdd("d", 1, CDate([Forms]![YourForm]![txtDate]))

>

Thanks, John -
My apologies, I should have been more specific.
I've got a Jet BE and Delphi front end. What I need is a SQL select query, returning
a recordset.
 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      29th Oct 2008
On Wed, 29 Oct 2008 17:57:46 -0400, MikeR <(E-Mail Removed)> wrote:

>My apologies, I should have been more specific.
>I've got a Jet BE and Delphi front end. What I need is a SQL select query, returning
>a recordset.


I don't know Delphi, but you should be able to construct a SQL string with the
desired date; add 1 (one day) to the date to get the next date, and use a
criterion such as

>= {the selected date} AND < {the selected date} + 1


--

John W. Vinson [MVP]
 
Reply With Quote
 
MikeR
Guest
Posts: n/a
 
      30th Oct 2008
John W. Vinson wrote:
> On Wed, 29 Oct 2008 17:57:46 -0400, MikeR <(E-Mail Removed)> wrote:
>
>> My apologies, I should have been more specific.
>> I've got a Jet BE and Delphi front end. What I need is a SQL select query, returning
>> a recordset.

>
> I don't know Delphi, but you should be able to construct a SQL string with the
> desired date; add 1 (one day) to the date to get the next date, and use a
> criterion such as
>
>> = {the selected date} AND < {the selected date} + 1

>

Delphi is actually irrelevant. I'm talking to the BE with DAO. I don't see how the
date can be = and < at the same time. ;-)
SELECT *
FROM Log
WHERE mge = 'AZ1' and LDate = #01/01/1983# and LDate < #01/02/1983#

returns nothing.
 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      30th Oct 2008
On Wed, 29 Oct 2008 20:29:56 -0400, MikeR <(E-Mail Removed)> wrote:

>Delphi is actually irrelevant. I'm talking to the BE with DAO. I don't see how the
>date can be = and < at the same time. ;-)
>SELECT *
>FROM Log
>WHERE mge = 'AZ1' and LDate = #01/01/1983# and LDate < #01/02/1983#
>
>returns nothing.


The point is that tje 1/1/1983 in your query is actually 30317.0000000000,
and the #01/01/1983 11:45 am# in your table is really 30317.4895833333. Those
two numbers are NOT equal so the record is not returned.

You want to find dates for which the stored value is between 30317 and 30318,
or to be more precise, greater than or equal (>= is the symbol) than 30317 and
less than 30318.

WHERE mge = 'AZ1' and LDate >= #01/01/1983# and LDate < #01/02/1983#

or, equivalently,

WHERE mge = 'AZ1' and LDate >= #01/01/1983# and LDate < #01/01/1983# + 1

will get you your desired result.
--

John W. Vinson [MVP]
 
Reply With Quote
 
MikeR
Guest
Posts: n/a
 
      30th Oct 2008
John W. Vinson wrote:
> On Wed, 29 Oct 2008 20:29:56 -0400, MikeR <(E-Mail Removed)> wrote:
>
>> Delphi is actually irrelevant. I'm talking to the BE with DAO. I don't see how the
>> date can be = and < at the same time. ;-)
>> SELECT *
>>FROM Log
>> WHERE mge = 'AZ1' and LDate = #01/01/1983# and LDate < #01/02/1983#
>>
>> returns nothing.

>
> The point is that tje 1/1/1983 in your query is actually 30317.0000000000,
> and the #01/01/1983 11:45 am# in your table is really 30317.4895833333. Those
> two numbers are NOT equal so the record is not returned.
>
> You want to find dates for which the stored value is between 30317 and 30318,
> or to be more precise, greater than or equal (>= is the symbol) than 30317 and
> less than 30318.
>
> WHERE mge = 'AZ1' and LDate >= #01/01/1983# and LDate < #01/02/1983#
>
> or, equivalently,
>
> WHERE mge = 'AZ1' and LDate >= #01/01/1983# and LDate < #01/01/1983# + 1
>
> will get you your desired result.


Thanks for the explanation John -
It's now firmly in the thick skull. Works a treat.
Mike
 
Reply With Quote
 
Guest
Posts: n/a
 
      9th Nov 2008


"MikeR" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> John W. Vinson wrote:
>> On Wed, 29 Oct 2008 17:57:46 -0400, MikeR <(E-Mail Removed)> wrote:
>>
>>> My apologies, I should have been more specific.
>>> I've got a Jet BE and Delphi front end. What I need is a SQL select
>>> query, returning a recordset.

>>
>> I don't know Delphi, but you should be able to construct a SQL string
>> with the
>> desired date; add 1 (one day) to the date to get the next date, and use a
>> criterion such as
>>
>>> = {the selected date} AND < {the selected date} + 1

>>

> Delphi is actually irrelevant. I'm talking to the BE with DAO. I don't see
> how the date can be = and < at the same time. ;-)
> SELECT *
> FROM Log
> WHERE mge = 'AZ1' and LDate = #01/01/1983# and LDate < #01/02/1983#
>
> returns nothing.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Date For Query =?Utf-8?B?VG9tbXkyMzI2?= Microsoft Access Queries 2 13th Sep 2007 03:34 PM
Help with query to select the maximum date from a query graeme34 via AccessMonster.com Microsoft Access Queries 9 19th Mar 2006 09:57 PM
Select date query Abay Microsoft Access Queries 5 6th Nov 2005 07:33 AM
how do I run a query to select most recent date(s) from several . =?Utf-8?B?bWFyb3NlNzA=?= Microsoft Access Queries 1 12th Mar 2005 08:30 PM
Need query to select max effective date based on date range M Skabialka Microsoft Access Forms 1 23rd Jan 2004 12:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:27 PM.