I'm receiving date values(as string) from one of the source system. It is always a 8 char long as shown below. I'm really not sure why they have kept in this format.
15/06-10
07/03-03
28/10-04
10/07-90
05/07-55
But for my application, I need to convert this into a proper date format(i.e. DD-MON-YYYY).
- First 2 characters represent
Date - Next 2 characters(after
/) representMonth - last 2 represent
year
In oracle, I can use to_date to achieve this. Something like
select to_date('15/06-10','yy/mm-dd') from dual;
But in SQL Server, I couldn't find such function. Is there a way to achieve this? The closest I have got is
DECLARE @d VARCHAR(100) = '15/06-10';
SELECT DATEFROMPARTS('20'+SUBSTRING(@d,7,2),SUBSTRING(@d,4,2),SUBSTRING(@d,1,2))
I'm not sure if this is the right way. Also It is giving the results only when I hardcode 20 for the year. But i'm getting data from 1950. So I cannot hardcode 19 or 20 Expected output for above sample is
+----------+-------------+
| 15/06-10 | 15-JUN-2010 |
+----------+-------------+
| 07/03-03 | 07-MAR-2003 |
+----------+-------------+
| 28/10-04 | 28-OCT-2004 |
+----------+-------------+
| 10/07-90 | 10-JUL-1990 |
+----------+-------------+
| 05/07-55 | 05-JUL-1955 |
+----------+-------------+
19or20? Suppose if the data is10/07-19, then do you expect10-JUL-2019or10-JUL-1919? That is the reason you should always use 4 digit format.50to99i want to19and01to20i want20. For this10/07-19, i need10-JUL-2019@ArunPalanisamy