views:

62

answers:

2

Hi,

I have an sql stored procedure which accepts two dates, however when I send them in my open query, oracle does not like the date format for some reason....

How can I change the dateformat to YYYY-MM-DD from dd-mm-yyyy in the stored procedure before sending using it.

e.g SET @startdate = CONVERT??

Thanks,

Tina

+3  A: 

Use the TO_DATE function to convert a string value into an Oracle DATE data type.

To accept a date string in the format YYYY-MM-DD:

v_start_date DATE := TO_DATE(v_date_string, 'YYYY-MM-DD');

To accept a date string in the format DD-MM-YYYY:

v_start_date DATE := TO_DATE(v_date_string, 'DD-MM-YYYY');
OMG Ponies
A: 

You can use TO_CHAR function of Oracle.

/*retrieve from query*/
select TO_CHAR(reg_date,'YYYY-MM-DD') REGDATE from Users_TBL 

/*Assign to variable*/
regDate := TO_CHAR(reg_date,'YYYY-MM-DD');
ppshein
If Oracle's not accepting the format, it's not an issue with an existing DATE value.
OMG Ponies
TO_DATE function doesn't work for "YYYY-MM-DD" format. That's why try to use "TO_CHAR" instead of "TO_DATE".
ppshein
"`YYYY-MM-DD`" is perfectly fine for both TO_DATE and TO_CHAR. It just depends on which direction you're converting between date and string.
Jeffrey Kemp