# Mysql query on date as string

**URL:** <https://www.phphelp.com/t/mysql-query-on-date-as-string/34333>\
**Category:** MySQL database\
**Created:** [December 2, 2021, 2:50pm UTC](https://www.phphelp.com/t/mysql-query-on-date-as-string/34333 "2021-12-02T14:50:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marco77](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@marco77](https://www.phphelp.com/u/marco77)\
**Post date:** [December 2, 2021, 2:50pm UTC](https://www.phphelp.com/t/mysql-query-on-date-as-string/34333/1 "2021-12-02T14:50:45Z")

</div>

Hi, I have my database with date records saved as string.  
For example 021221 is the string and represent 2 december 2021.  
Now i need to create a query that select rows by considering that string date + 5 days.

I know how to do with date records… so saved as date… but in my case how to do when records are saved as string?

thanks for your help

```auto
    $sql = "select * from tablename where item like str_to_date('021221','%d%m%Y') as date"; 

```

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [December 2, 2021, 4:57pm UTC](https://www.phphelp.com/t/mysql-query-on-date-as-string/34333/2 "2021-12-02T16:57:15Z")

</div>

First thing to do is stop saving dates that way. Use a proper date type column then you can use the numerous built-in date functions.
