Re: Easy Date Searching Question

From: From the terminal emulator of Andrew Dowswell <dowswea_at_aa.wl.com>
Date: 31 Aug 93 15:04:36 -0500
Message-ID: <1993Aug31.150436.1_at_aa.wl.com>


In article <CCJ729.Apz_at_vistachrome.com>, andy_at_vistachrome.com (Andrew Finkenstadt) writes:
> ditommm_at_aa.wl.com (Mr. Matteo diTommaso) writes:

>>Table Emp:
>>Ename char(100)
>>InDate date
>>Find all employees added 12/23/92 (any time of day).
>>select Ename
>> from Emp
>>where InDate = '23-DEC-92';
 
>>Will fail?

>
> Yes. Unless added at midnight. Use this:
>
> SELECT ename
> FROM emp
> WHERE indate between '23-dec-92' and '23-dec-92'+1
> ;
>
>
>>Thanks.
>>-- 
>>| Matteo diTommaso  (ditommm_at_aa.wl.com) |       /|                            |
>>| Ann Arbor, MI, USA                    |   \'o.O'      This space for rent.  |
>>| Phone: (313) 996-7148                 |   =(___)=                           |
>>| (Full disclaimer available by e-mail) |       U  ACK! THPTPHH!              |

> --
> Andrew Finkenstadt | andy_at_{homes.com,vistachrome.com,genie.geis.com}
> Systems Analyst | Vista-Chrome, Homes & Land Publishing Corporation
> | 1600 Capital Circle SW, Tallahassee Florida 32310
> +1 904-575-0189 | GEnie Postmaster, Unix & Internet RoundTables Sysop

Mr diTommaso,

The other thing you might consider here is the question "Do I really need the timestamp on this date?". If the answer is no, and you have access to the data and the sources of the data, you can TRUNC the dates. By using TRUNC(Date) when the data is entered into the database, all the dates will have the default time value (midnight) on them. Your original example would then work perfectly fine and the code would be clear, concise, and understandable. Unfortunately, this is usually not an option unless you are still in the design phase.

Andy

-- 
 /---------------------------------------------------------------------------\
 | Andrew Dowswell     | "...They bring me numbness in their bright needles, |
 | Parke-Davis (CPO)   |  they bring me sleep. Now I have lost myself..."    |
 | dowswea_at_aa.wl.com   |                                                     |
 | (313) 996-1337      |             Sylvia Plath "Tulips"                   |
 \---------------------------------------------------------------------------/
Received on Tue Aug 31 1993 - 22:04:36 CEST

Original text of this message