Date field issue

Solved
Hello everyone,

After hours on the internet searching for my answer, I finally decide to ask my question directly.

I invite the users of my site, in a form, to indicate a certain date. This field specifies a format like 20/08/2018. However, in my database, the format is 2018-08-20.

What should I do?

Thank you in advance.

1 answer

  1. Moderator
    Hello

    You just need to reformat the date into a timestamp so that it can be correctly inserted into your database...
    For example:
     $date="20/08/2018"; $date = explode("/", $date); $newsdate=$date[2].'-'.$date[1].'-'.$date[0]; 


    Or
     $date="20/08/2018"; $newdate = date('Y-m-d', strtotime($date)); 


    Alternatively, in your SQL query, it should also be possible to use STR_TO_DATE:
     STR_TO_DATE('20/08/2018', '%d/%m/%Y') 


    --
    Best regards,
    Jordane
    1. Hello,

      Thank you for your response, I understand where you're coming from, I will try that right now!
    2. It's all good,

      thank you for your help!
    3. Moderator
      Think about marking the subject as RESOLVED (via the gear icon at the top right of your title)