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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.