HELP !!! SYSDATE 
Author Message
 HELP !!! SYSDATE
I need help. Bellow, after I execute the code below on Saturday and
Sunday, I get a return of WEEKDAY. Can someone suggest why it's not
returning WEEKDAY

IF TO_CHAR(V_Sysdate, 'DAY') IN  ('SATURDAY', 'SUNDAY')
   THEN
      DBMS_OUTPUT.PUT_LINE(' WEEKEND ');
   ELSE
   DBMS_OUTPUT.PUT_LINE(' WEEKDAY  ');

END IF;

Thanks for any input

Zuin

Sent via Deja.com http://www.***.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT
 HELP !!! SYSDATE



Quote:
> I need help. Bellow, after I execute the code below on Saturday and
> Sunday, I get a return of WEEKDAY. Can someone suggest why it's not
> returning WEEKDAY

> IF TO_CHAR(V_Sysdate, 'DAY') IN  ('SATURDAY', 'SUNDAY')
>    THEN
>       DBMS_OUTPUT.PUT_LINE(' WEEKEND ');
>    ELSE
>    DBMS_OUTPUT.PUT_LINE(' WEEKDAY  ');

> END IF;

> Thanks for any input

> Zuin

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Hello
Just one change is required
rtrim(TO_CHAR(V_Sysdate, 'DAY'))

char adds an additional character at the end of the day name which is
the character delimiter. That is why your comparison nevers evaluates to
true.
As a general rule, its always good to use ltrim and rtrim functions when
doing character comparisons.

Cheers

--
Owais Anjum
Senior Software Engineer
Kaps Computing, Pakistan

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT
 HELP !!! SYSDATE
Maybe the language isn't english.
Try
select to_char(sysdate,'DAY','NLS_DATE_LANGUAGE=english')

If This doesn't help I think the date isn't the deate you expected to
be.

Quote:

> I need help. Bellow, after I execute the code below on Saturday and
> Sunday, I get a return of WEEKDAY. Can someone suggest why it's not
> returning WEEKDAY

> IF TO_CHAR(V_Sysdate, 'DAY') IN  ('SATURDAY', 'SUNDAY')
>    THEN
>       DBMS_OUTPUT.PUT_LINE(' WEEKEND ');
>    ELSE
>    DBMS_OUTPUT.PUT_LINE(' WEEKDAY  ');

> END IF;

> Thanks for any input

> Zuin

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT
 HELP !!! SYSDATE

Quote:



>> I need help. Bellow, after I execute the code below on Saturday and
>> Sunday, I get a return of WEEKDAY. Can someone suggest why it's not
>> returning WEEKDAY

>> IF TO_CHAR(V_Sysdate, 'DAY') IN  ('SATURDAY', 'SUNDAY')
>>    THEN
>>       DBMS_OUTPUT.PUT_LINE(' WEEKEND ');
>>    ELSE
>>    DBMS_OUTPUT.PUT_LINE(' WEEKDAY  ');

>> END IF;

>> Thanks for any input

>> Zuin

>> Sent via Deja.com http://www.deja.com/
>> Before you buy.

>Hello
>Just one change is required
>rtrim(TO_CHAR(V_Sysdate, 'DAY'))

>char adds an additional character at the end of the day name which is
>the character delimiter. That is why your comparison nevers evaluates to
>true.

Your solution is correct but your reason why is wrong.  to_char does not
add additional characters.  What actually is happening is that
to_char of a date returning format 'DAY' will return a string that is as long
as the longest possible value, 'WEDNESDAY'.

Here's a query to show what I mean.


  2  from all_objects
  3  where rownum < 8;

DAY
-----------
*SATURDAY *
*SUNDAY   *
*MONDAY   *
*TUESDAY  *
*WEDNESDAY*
*THURSDAY *
*FRIDAY   *

WEDNESDAY has no extra spaces but SUNDAY, MONDAY,
and FIRDAY each have three.

The same is true for the format 'MONTH'.


  2  from all_objects
  3  where rownum < 13;

MONTH
-----------
*NOVEMBER *
*DECEMBER *
*JANUARY  *
*FEBRUARY *
*MARCH    *
*APRIL    *
*MAY      *
*JUNE     *
*JULY     *
*AUGUST   *
*SEPTEMBER*
*OCTOBER  *

hope this clears things up.

chris.

Quote:
>As a general rule, its always good to use ltrim and rtrim functions when
>doing character comparisons.

>Cheers

--
Christopher Beck
Oracle Corporation

Reston, VA.
----------------------------------------------------------------------------
Opinions are mine and do not necessarily reflect those of Oracle Corporation


Wed, 18 Jun 1902 08:00:00 GMT
 HELP !!! SYSDATE


Quote:
> I need help. Bellow, after I execute the code below on Saturday and
> Sunday, I get a return of WEEKDAY. Can someone suggest why it's not
> returning WEEKDAY

> IF TO_CHAR(V_Sysdate, 'DAY') IN  ('SATURDAY', 'SUNDAY')
>    THEN
>       DBMS_OUTPUT.PUT_LINE(' WEEKEND ');
>    ELSE
>    DBMS_OUTPUT.PUT_LINE(' WEEKDAY  ');

> END IF;

Use TO_CHAR(V_Sysdate, 'fmDAY').
The 'DAY' date format will return a string of 9 characters, padded with
blanks.


Wed, 18 Jun 1902 08:00:00 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. Help with SYSDATE

2. trunc sysdate help please

3. SYSDATE in SQL Server?

4. backup database with sysdate

5. SYSDATE

6. how to convert (Oracle ) where trx_date = TRUNC(sysdate) to sql server 7

7. Sysdate counterpart in postgres

8. sysdate question????????

9. SQL and SYSDATE

10. SYSDATE function in Local SQL

11. SYSDATE

12. sysdate PreparedStatement problem


 
Powered by phpBB® Forum Software