startupsmith
startupsmith

Reputation: 5764

PHP Convert string from dd/mm/yyyy to YYYY-MM-DD HH:MM:SS string for use with ms sql server?

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?

Upvotes: 0

Views: 6742

Answers (3)

Waqar Alamgir
Waqar Alamgir

Reputation: 9968

// 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;

Upvotes: 0

YuS
YuS

Reputation: 2045

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

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

Upvotes: 2

Shakti Singh
Shakti Singh

Reputation: 86366

You can use the date and strtotime functions

$date=date('Y-m-d h:i:s', strtotime($date_in_ddmmyyyy));

Upvotes: 3

Related Questions