473,466 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

no output for to_date function

15 New Member
Hi,

I want to diaplay hi message if system date is equl to given date.
I tried one simple script.
But it doesn't show any output

what is problem with to_date function.

script:
*********************
Expand|Select|Wrap|Line Numbers
  1.  
  2. set serveroutput on
  3.  
  4. begin
  5.  
  6. if sysdate=to_date('23-11-2007','DD-MM-YYYY')  then
  7. dbms_output.put_line('Hi');
  8.  
  9. end if;
  10.  
  11. end;
  12.  
  13.  
SQL> @hai.sql

PL/SQL procedure successfully completed.
Nov 23 '07 #1
5 1877
amitpatel66
2,367 Recognized Expert Top Contributor
Hi,

I want to diaplay hi message if system date is equl to given date.
I tried one simple script.
But it doesn't show any output

what is problem with to_date function.

script:
*********************
set serveroutput on

begin

if sysdate=to_date('23-11-2007','DD-MM-YYYY') then
dbms_output.put_line('Hi');

end if;

end;

SQL> @hai.sql

PL/SQL procedure successfully completed.
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. select 1 from dual WHERE TO_DATE(SYSDATE,'DD-MM-YYYY') = TO_DATE('23-11-2007','DD-MM-YYYY')
  3.  
  4. SQL> /
  5.  
  6.         1
  7. ---------
  8.         1
  9.  
  10. select 1 from dual WHERE TRUNC(SYSDATE) = TO_DATE('23-11-2007','DD-MM-YYYY')
  11.  
  12. SQL> /
  13.  
  14.         1
  15. ---------
  16.         1
  17.  
  18.  
You need to either TRUNCATE the SYSDATE or convert the SYSDATE to the particular format for perfect comparisons.
Nov 23 '07 #2
nramrits
18 New Member
Hi,

I want to diaplay hi message if system date is equl to given date.
I tried one simple script.
But it doesn't show any output

what is problem with to_date function.

script:
*********************
set serveroutput on

begin

if sysdate=to_date('23-11-2007','DD-MM-YYYY') then
dbms_output.put_line('Hi');

end if;

end;

SQL> @hai.sql

PL/SQL procedure successfully completed.
hi
please use the to_date funtion in sysdate , because sysdate contain a time , min,seconds so that the if condition is return false.
if to_date(sysdate) =to_date('23-11-2007','DD-MM-YYYY') then
Nov 23 '07 #3
amitpatel66
2,367 Recognized Expert Top Contributor
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Nov 23 '07 #4
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

There is no need to convert it to date both sides, check this way :

Expand|Select|Wrap|Line Numbers
  1. set serveroutput on
  2. begin
  3. IF TO_CHAR(SYSDATE,'DD-MM-YYYY') ='23-11-2007'  THEN
  4.     dbms_output.put_line('Hi');
  5. end if;
  6. end;
  7.  
Regards
Veena
Nov 23 '07 #5
Dharmaraju
13 New Member
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. select 1 from dual WHERE TO_DATE(SYSDATE,'DD-MM-YYYY') = TO_DATE('23-11-2007','DD-MM-YYYY')
  3.  
  4. SQL> /
  5.  
  6.         1
  7. ---------
  8.         1
  9.  
  10. select 1 from dual WHERE TRUNC(SYSDATE) = TO_DATE('23-11-2007','DD-MM-YYYY')
  11.  
  12. SQL> /
  13.  
  14.         1
  15. ---------
  16.         1
  17.  
  18.  
You need to either TRUNCATE the SYSDATE or convert the SYSDATE to the particular format for perfect comparisons.

/****************** TRY THIS********************/

hi may be the time part will not match to that date so use truncate for sysdate then we can compare the condition

set serveroutput on
begin
select trunc(to_date(sysdate))=to_date('03/12/2007','dd/mm/yyyy') from dual;
dbms_output.put_line('hi');
end;

/******************** I THINK IT CAN BE USE******************/
Dec 3 '07 #6

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

Similar topics

2
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
1
by: Amin Schoeib | last post by:
Hi, Can somebody tell me why this query don't work when I use to_date Instead of to_char By using to_char: select to_char(last_day(cast(current_date - interval '1 month' as...
1
by: kaab kaoutar | last post by:
Hi, A client is using postgresql 7.1.3, and to_date() and to_timestamp() functions fail sometimes,However they never do in postgresql 7.3.2. Are these bugs? Thx ...
2
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....
5
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...
1
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...
3
rsrinivasan
by: rsrinivasan | last post by:
hi, I used the following query, select to_date('31-12-2006 23:34:59','DD-MM-YYYY HH24:MI:SS') from dual; but i get only 31-DEC-06 why i did not get the time....
0
by: woodsc | last post by:
Hi all, I am trying to optimize the queries in my application. Is there a performance difference between (to_char(myDate,format) < myString) and (myDate < to_date(myString, format)). ex. ...
4
by: hydroraven | last post by:
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. ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.