I'm trying to go in a if condition in PLSQL when certaint dates are on a specific day in the week.
DECLARE
v_gebDatum CONSTANT DATE := to_date('21-01-1995', 'dd-MM-yyyy');
v_mathDatum DATE := v_gebDatum;
v_huidigeDag VARCHAR2(20);
v_teller number := 0;
BEGIN
WHILE to_char(v_mathDatum, 'yyyy') < to_char(sysdate, 'yyyy')
LOOP
v_mathDatum := add_months(v_mathDatum, 12);
v_huidigeDag := to_char(v_mathDatum, 'DAY');
dbms_output.put_line(v_huidigeDag);
IF v_huidigeDag IN('ZATERDAG', 'ZONDAG')
THEN
dbms_output.put_line(v_mathDatum);
END IF;
END LOOP;
END;
Problem is that I can't get this to work. When printing the v_huidigeDag it clearly has the values 'ZATERDAG and 'ZONDAG' in some of the printed lines.
It appears that, for some reason when I printed the values for daynames the program added spaces in. I guess it takes the char length for the longest day name ('DONDERSDAG') in my Locale. And everything with less characters than that it adds spaces. So zaterdag becomes = 'ZATERDAG ' and zondag becomes = 'ZONDAG '. Now it's working but does somebody know an easy way to prevent this?
The problem is with the
DAY
format. According to the date format documentation:To disable that behavior, you have to use the
FM
modifier:In your particular case: