0

I am hosting a php application on Windows server 2008 and using SQL Server 2008. I am having issues with inserting dd/mm/yyyy date strings in to the database.

How can I manually convert my dd/mm/yyyy string into the MS SQL Server date format YYYY-MM-DD HH:MM:SS within PHP code?

3 Answers 3

3

You can use the date and strtotime functions

$date=date('Y-m-d h:i:s', strtotime($date_in_ddmmyyyy));
Sign up to request clarification or add additional context in comments.

Comments

2
$date = strtotime('11/01/2012');

$new_date = date('Y-m-d H:i:s', $date);

Comments

0

// e.g. '12/12/2040' will not work

$date = strtotime('12/12/2035');

if($date !== false)
{
    $date = date('Y-m-d h:i:s' , $date);
}
else
{
    $date = 'can\'t convert';
}
echo $date;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.