Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2008
    Posts
    464

    Unanswered: specifying the datetime....9i

    Hi guys

    Recently, I got help on specifying a one month period as:

    Code:
    where to_char(datetime, 'mm.yyyy') = to_char(add_months(sysdate, -1), 'mm.yyyy')
    
    group by to_char(DATETIME,'MM/YYYY'), bsc
    Could someone please help me specify a period of 1 year? Like 1 JAN 2009 to 31 DEC 2009.

    Thanks

    Regards

  2. #2
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Code:
    where datetime between to_date('01012009,'mmddyyyy') and to_date('12312009','mmddyyyy')
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  3. #3
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Quote Originally Posted by beilstwh View Post
    Code:
    where datetime between to_date('01012009,'mmddyyyy') and to_date('12312009','mmddyyyy')
    What about the last 23 hours, 59 minutes & 59 seconds of 31-DEC not being included in above range?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  4. #4
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    they didn't specify they wanted a time element, but if they do then
    Code:
    where datetime between to_date('01012009,'mmddyyyy') and to_date('12312009235959','mmddyyyyhh24miss')
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,296
    RE: OP
    i don't recommend adding functions like to_char to date fields in where clauses. If there is a good deal of data then your response times will suffer with full table scans.

    modify your comparisons to match your column fields like Bill showed.

    what sometimes looks like a simple answer can cause a lot of issues down the road.
    example:
    PHP Code:
     to_char(date_column'YYYY') = '2009' 
    looks innocent enough but ...
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  6. #6
    Join Date
    Aug 2008
    Posts
    464
    Thanks guys...Appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •