• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Date in Oracle query

I am again stuck trying to find a format to use date in a query.
The field is DATE, the database is ORACLE.

I am trying SR_DT >= '02/14/2009'
and getting "invalid month" no matter what I variation:
'2/14/09' '02/14/2009'
Without the date, the query runs fine...
PLEASE! help?                  :)   Thanks, Beth
0
ba_trainer
Asked:
ba_trainer
  • 4
  • 2
1 Solution
 
HainKurtSr. System AnalystCommented:
use this

select to_date('02/14/2009', 'fmMM/DD/YYYY') from dual
0
 
Kevin CrossChief Technology OfficerCommented:
What date format is your system using.  If it is DD/MM/YYYY then all of those would fail as 14 would be an invalid month.

Try :

SR_DT >= '2009-02-14'

or

SR_DT >= '20090214'

or (even better)

SR_DT >= TO_DATE('02/14/2009', 'MM/DD/YYYY')
http://www.techonthenet.com/oracle/functions/to_date.php
0
 
Kevin CrossChief Technology OfficerCommented:
*laughing* Guess HainKurt and I had the same thought.  Hopefully you get the gist from the two examples.  Judging from the 'SR_DT >=' portion you have this in a where clause of a bigger query, the 'FROM DUAL' won't be needed but to test standalone you can run HainKurt's code as is to see what it is doing.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ba_trainerAuthor Commented:
Thanks!!
0
 
HainKurtSr. System AnalystCommented:
but why you got all the points and I got nothing ;(
0
 
Kevin CrossChief Technology OfficerCommented:
Not sure.  Maybe the asker simply missed the comment as we pretty much posted same time (at least - your comment wasn't there when I started typing).  Anyway, sorry that happened. :)
0
 
Kevin CrossChief Technology OfficerCommented:
Although it may not have been clear how to implement your suggestion without any explanation.  If you through in your posted code into the existing query they had, there would be an error from the additional 'select' and 'from dual' portions.  Never hurts to explain a bit. ;)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now