I have a column where a date store in ddmmyy format (e.g. 151216). How can I convert it to yyyy-mm-dd format (e.g 2016-12-15) for calculating a date difference from the current date? I try using DATE\_FORMAT function but its not appropriate for this.
['https://Stackoverflow.com/questions/45003631', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2231075/']
If you want to get the date difference, you can use `to_days()` after converting the string to a date using `str_to_date()`:

```
select to_days(curdate()) - to_days(str_to_date(col, '%d%m%y'))

```

or `datediff()`:

```
select datediff(curdate(), str_to_date(col, '%d%m%y'))

```

or `timestampdiff()`:

```
select timestampdiff(day, str_to_date(col, '%d%m%y'), curdate())

```
You can use the function, `STR_TO_DATE()` for this.

```
STR_TO_DATE('151216', '%d%m%y')

```

A query would look something like:

```
select
    foo.bar
from
    foo
where
    STR_TO_DATE(foo.baz, '%d%m%y') < CURDATE()

```

Note: Since both `STR_TO_DATE()` and `CURDATE()` return date objects, there's no reason to change the actual display format of the date. For this function, we just need to format it. If you wanted to display it in your query, you could use something like 

```
DATE_FORMAT(STR_TO_DATE(foo.baz, '%d%m%y'), '%Y-%m-%d')

```

To get the difference, we can simply subtract time

```
select 
    to_days(CURDATE() - STR_TO_DATE(foo.baz, '%d%m%y')) as diff
from
    foo

```

If you wanted to only select rows that have a difference of a specified amount, you can put the whole `to_days(...)` bit in your where clause.