473,657 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having a problem with the TO_DATE function in Oracle.

2 New Member
Hello all,

I am trying to use the TO_DATE function to convert a string to a date so that I can perform periodic maintenance on a table based upon the date.

Here is the SQL statement.
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * FROM APPROVED
  3. WHERE TO_DATE(CREATION_TIME, 'DY MON DD HH24:MI:SS TZD YYYY') > SYSDATE-30
  4.  
  5.  
Here is the actual string value 'Mon Dec 10 15:20:25 EDT 2007'

When I execute the query I get the following message "ORA-01821: date format not recognized".

I thought since I was specifying the format Oracle would be able to make sense of my date string. Does anyone see any flaws or able to offer some pointers?

Any help is appreciated.
Dec 10 '07 #1
4 10323
debasisdas
8,127 Recognized Expert Expert
What is the data type of CREATION_TIME field.

try to use
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * FROM APPROVED
  3. WHERE TO_DATE(CREATION_TIME, 'DD-MON-YY HH12:MI:SS') > SYSDATE-30
  4.  
  5.  
Dec 11 '07 #2
hydroraven
2 New Member
What is the data type of CREATION_TIME field.

try to use
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * FROM APPROVED
  3. WHERE TO_DATE(CREATION_TIME, 'DD-MON-YY HH12:MI:SS') > SYSDATE-30
  4.  
  5.  

The datatype of the CREATION_TIME is VARCHAR2. I tried the code you provided but it did not work.

The error message I get is ORA-01858: a non-numeric character was found where a numeric was expected.

Hope this helps. Thanks
Dec 11 '07 #3
amitpatel66
2,367 Recognized Expert Top Contributor
Hello all,

I am trying to use the TO_DATE function to convert a string to a date so that I can perform periodic maintenance on a table based upon the date.

Here is the SQL statement.
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * FROM APPROVED
  3. WHERE TO_DATE(CREATION_TIME, 'DY MON DD HH24:MI:SS TZD YYYY') > SYSDATE-30
  4.  
  5.  
Here is the actual string value 'Mon Dec 10 15:20:25 EDT 2007'

When I execute the query I get the following message "ORA-01821: date format not recognized".

I thought since I was specifying the format Oracle would be able to make sense of my date string. Does anyone see any flaws or able to offer some pointers?

Any help is appreciated.
Could you please provide few more values of creation_date column?
And also please clarify what does that EDT refers to?

I tried this and it works:
Expand|Select|Wrap|Line Numbers
  1. SQL> alter session set nls_Date_format='Dy Mon DD HH24:MI:SS RRRR'
  2.   2  /
  3.  
  4. Session altered.
  5.  
  6. SQL> select TO_DATE('Mon Dec 10 15:20:25 2007') from dual
  7.   2  /
  8.  
  9. TO_DATE('MONDEC1015:20:2'
  10. ------------------------
  11. Mon Dec 10 15:20:25 2007
  12.  
  13. -- Now again if I alter my date format, it will error out as shown below:
  14.  
  15. SQL> alter session set nls_date_format='DD-MON-RRRR'
  16.   2  /
  17.  
  18. Session altered.
  19.  
  20. SQL> select TO_DATE('Mon Dec 10 15:20:25 2007') from dual
  21.   2  /
  22. select TO_DATE('Mon Dec 10 15:20:25 2007') from dual
  23.                *
  24. ERROR at line 1:
  25. ORA-01858: a non-numeric character was found where a numeric was expected
  26.  
  27.  
Dec 12 '07 #4
amitpatel66
2,367 Recognized Expert Top Contributor
You need not alter the session also. Try this:

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1* select TO_DATE('Mon Dec 10 15:20:25 2007','Dy Mon DD HH24:MI:SS RRRR') from dual
  5. SQL> /
  6.  
  7. TO_DATE('MO'
  8. -----------
  9. 10-DEC-2007
  10.  
  11. SQL> 
  12.  
Dec 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3757
by: Damjan | last post by:
I'm using Python 2.4, cx_Oracle-4.1 on Linux with Oracle instant client 10.1.0.3. This is the sql string: SQL = """insert into D.D_NOTIFY values (:CARDREF, :BANKKEY, :OK1, :OK2 \ :DEBTEUR, :DEBTDEN, to_date(:INVOICE_DATE,'DD.MM.YY'), to_date(:PAYMENT_DEADLINE,'DD.MM.YY'), :POINTS)""" And I'm trying to execute it as: c = db.cursor() c.execute(SQL, CARDREF=id, BANKKEY=dc_kluc, OK1=okd, OK2=okc,
2
25295
by: KULJEET | last post by:
hi i have a table c_table with two columns no, date it contains records no n_date 1 10-AUG-03 2 21-AUG-03
0
2597
by: Max | last post by:
Hi wise people, Has anyone encountered the Crystal Reports problem I describe below? If so, how did you solve it? It seems that every article posted on google regarding CR and logon problems is still unanswered. I think I'm cursed. I originally created a crystal report which connects to a sql server server db on the same dev machine and it worked just fine. I tried to move it to another computer, but now I have to connect to an Oracle...
2
18381
by: gimme_this_gimme_that | last post by:
Assuming data is being stored in a DB2 TIMESTAMP what is the equivalent of Oracle's to_date function : to_date('03/04/2005','MM/DD/YYYY') It's OK if MM/DD/YYYY is the only supported format. Thanks.
5
4610
by: gane kol | last post by:
Hi when i try to use to_date function in C# codebehind, i am getting to_date doesnt exist in class or namespace error. i am trying to use something similar to INSERT INTO OracleTypesTable VALUES ( 'test', 2, to_date('2000-01-11 12:54:01','yyyy-mm-dd hh24:mi:ss'), '0001020304' )"; ref link:
1
2419
by: TANUJ | last post by:
i m working on oracle forms 6i n enable to fetch the record in time format. on form, field type is date with format mask hh24:mi but when i fetch it using to_char function nd trans it into to_date func only date show.. not time.. help me.. tanuj
14
4431
by: peteh | last post by:
Hi All; We have many production jobs that "load from cursor" to a UDB/AIX 8.2 (with dpf) data warehouse from source tables residing Oracle 9i. Since Oracle dates are (roughly) equivalent to DB2 timestamps, we frequently use the date() function to "convert" from the Oracle date datatype to the DB2 date datatype. We have used this technique on over 20 Oracle tables for several months with no problem. One table in particular fails with a...
0
2080
by: Lenny | last post by:
Hi. I've a problem with an update from the sqldatasource the table cannot be modified because it is from a third party sw table fields are: codice, fcli_inizio, fcli_fine. keys are codice and fcli_inizio when I run the update the field fcli_fine (not key) is updated but not the fcli_inizio. this is the code. db is in oracle.
14
2633
by: ESHA1 | last post by:
CREATE OR REPLACE procedure TEST_EMAIL(errbuf OUT VARCHAR2, retcode OUT VARCHAR2, p_from_date date, p_to_date date, P_CANDIDATE_NAME VARCHAR2) as x_manager_name1 assignment.manager_name%type; x_EMAIL_ADDRESS candidate.EMAIL_ADDRESS%type; x_candidate_name1 assignment.candidate_name%TYPE; x_customer_name1 assignment.customer_name%TYPE; x_manager_name ...
0
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.