1

I have following query

select substring(listDate from '............$') as v_end_date,
substring(listDate from '^...............') as v_start_date

Now listDate value can be like

select substring('06 Jan 2014 to 12 Jan 2014,
 13 Jan 2014 to 19 Jan 2014,
 20 Jan 2014 to 26 Jan 2014
' from '............$') as v_end_date,
substring('06 Jan 2014 to 12 Jan 2014,
 13 Jan 2014 to 19 Jan 2014,
 20 Jan 2014 to 26 Jan 2014
' from '^............') as v_start_date

Above query results in

V_END_DATE  V_START_DATE
26 Jan 2014 06 Jan 2014

Now I need to have v_end_date and v_start_date format like yyyy-mm-dd and like Mon 06 Jan 2014.

1 Answer 1

5

Convert your string to an actual date with to_date() and use to_char() to get pretty much any format you like.

Demo:

SELECT to_char(day, 'YYYY-MM-DD')     AS format1
     , to_char(day, 'Dy DD Mon YYYY') AS format2 
FROM   (SELECT to_date('26 Jan 2014', 'DD Mon YYYY') AS day) sub
Sign up to request clarification or add additional context in comments.

1 Comment

Recommended. Never store dates in string format, you can not calculate dates and times with that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.