Date field issue

Solved
Jeremd89 Posted messages 12 Status Member -  
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   -
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

jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
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
0
Jeremd89 Posted messages 12 Status Member
 
Hello,

Thank you for your response, I understand where you're coming from, I will try that right now!
0
Jeremd89 Posted messages 12 Status Member
 
It's all good,

thank you for your help!
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
Think about marking the subject as RESOLVED (via the gear icon at the top right of your title)
0