Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 27th, 2006, 07:17 AM
gpn_prasad gpn_prasad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 1 gpn_prasad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 31 sec
Reputation Power: 0
Query regarding date & time

I wanted to know how to get all the records of a particular day between two times. For ex : I want all the records of 15th May 2006 between 10 am and 5 pm. The datatype used is date. Plz let me know the query if anyone knows....

Reply With Quote
  #2  
Old July 27th, 2006, 09:20 AM
marnixR's Avatar
marnixR marnixR is offline
i don't do negative rep
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2006
Posts: 657 marnixR User rank is Captain (20000 - 30000 Reputation Level)marnixR User rank is Captain (20000 - 30000 Reputation Level)marnixR User rank is Captain (20000 - 30000 Reputation Level)marnixR User rank is Captain (20000 - 30000 Reputation Level)marnixR User rank is Captain (20000 - 30000 Reputation Level)marnixR User rank is Captain (20000 - 30000 Reputation Level)marnixR User rank is Captain (20000 - 30000 Reputation Level)marnixR User rank is Captain (20000 - 30000 Reputation Level)marnixR User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 18 h 6 m 18 sec
Reputation Power: 227
have a look at this thread - it might do for starters

i know the thread is about oracle rdb, but there might be enough that is applicable to standard oracle

Reply With Quote
  #3  
Old July 27th, 2006, 09:42 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,067 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 4 Weeks 2 h 10 sec
Reputation Power: 281
You can compare dates with the usual operators, something like
... where your_date_col > to_date(your_lower_limit, it's format) ...

Reply With Quote
  #4  
Old August 3rd, 2006, 12:08 AM
puvi puvi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 2 puvi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 29 sec
Reputation Power: 0
Thumbs up Re:Query regarding date & time

Quote:
Originally Posted by gpn_prasad
I wanted to know how to get all the records of a particular day between two times. For ex : I want all the records of 15th May 2006 between 10 am and 5 pm. The datatype used is date. Plz let me know the query if anyone knows....



Hi,

Let us consider the table structure as


ID NAME Dat
---- ------------------------------ -----------------
1 Puvi 12-01-06 10:45:33
2 ss 2-01-06 12:45:56
3 dd 3-01-06 12:45:56

U can get the names of the people who have registered between 11 and 23 Hrs by using the below query

select name , to_char(dat,'dd-mm-yy') dat from test1 where to_char(dat,'hh24:mi:ss') between '11:00:00' and '23:00:00';

which will yeild
Name dat
---------------------------------
ss 12-01-06
dd 13-01-06

or if u need the name on a particular date then write this query

select name , to_char(dat,'dd-mm-yy')
from test1
where to_char(dat,'hh24:mi:ss') between '11:00:00' and '23:00:00'
and
to_char(dat,'dd-mm-yy')='12-01-06';

which yeilds,

NAME TO_CHAR(
------------------------------ --------
ss 12-01-06

Reply With Quote
  #5  
Old August 8th, 2006, 04:24 PM
mateoc15's Avatar
mateoc15 mateoc15 is offline
C A R D S
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: The 'Ville
Posts: 783 mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 9 h 53 m 52 sec
Reputation Power: 12
Be careful with the BETWEEN keyword (and <, <=, >, >= for that matter). BETWEEN is inclusive of both dates, but if you do

BETWEEN '01-JAN-2006' AND '31-JAN-2006'

you will get data between 00:00:00 on 01/01 and 23:59:59 01/30. Basically you won't get 01/31 data because you are using a truncated date. If you truly want inclusive you need to create the statement that way.
__________________
Reinventing the wheel again

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Query regarding date & time


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT