Jump to content

Convert dd/mm/yyyy to yyyy/mm/dd for mysql


frobak

Recommended Posts

Hi

 

I need to change a uk date dd/mm/yyyy to mysql format yyyy/mm/dd

 

I have a user form where they enter the date in dd/mm/yyyy string format, i want to take that string, and convert it to mysql format yyyy/mm/dd

 

Possible?

 

Ive searched for ages and havent found a solution that works.

 

Is there an easy solution to this? surely there must be

 

Cheers

Link to comment
Share on other sites

thanks for your reply.

 

So ive tried using the code you supplied, but im getting errors. Heres the code

 

$start_date_pre = $_POST['start_date'];

$arrDate = explode("/","$start_date_pre");

$start_date = "$arrDate[2] . / $arrDate[1] . / . $arrDate[0]";

$sql = "INSERT INTO vacancies SET
vacancy_id= '$_POST[vacancy_id]',
job_title= '$_POST[job_title]',
salary= '$_POST[salary]',
job_salary_range= '$_POST[job_salary_range]',
job_location= '$_POST[job_location]',
job_terms= '$_POST[job_terms]',
start_date= $start_date,
end_date= '$_POST[end_date]',
job_desc= '$_POST[job_desc]'";

 

Can you see where ive gone wrong?

Link to comment
Share on other sites

heres the code that worked for me.

 

$start_date_pre = $_POST['start_date'];

$arrDate = explode("/","$start_date_pre");

$start_date = $arrDate[2] . "/" . $arrDate[1] . "/" . $arrDate[0];

$sql = "INSERT INTO vacancies SET
vacancy_id= '$_POST[vacancy_id]',
job_title= '$_POST[job_title]',
salary= '$_POST[salary]',
job_salary_range= '$_POST[job_salary_range]',
job_location= '$_POST[job_location]',
job_terms= '$_POST[job_terms]',
start_date= '$start_date',
end_date= '$_POST[end_date]',
job_desc= '$_POST[job_desc]'";

 

Cheers for your help

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.