Created
August 13, 2013 19:53
-
-
Save xthiago/6224996 to your computer and use it in GitHub Desktop.
Transformar Datetime do SQL SERVER em DateTime do PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Esse pequeno trecho demonstra como converter um Datetime oriundo do SQL Server em | |
* um objeto do tipo DateTime do PHP. | |
*/ | |
// exemplo de data retornada pelo SQL Server | |
$dataSqlServer = 'Jul 30 2013 02:44:27:000PM'; | |
// formato reconhecida pelo PHP | |
$formato = 'M d Y H:i:s:uA'; | |
var_dump($dataSqlServer); | |
var_dump(DateTime::createFromFormat($formato)); | |
/* retornará ao brownser algo como: | |
string 'Aug 13 2013 16:48:58:000000PM' (length=29) | |
object(DateTime)[146] | |
public 'date' => string '2013-07-30 14:44:27' (length=19) | |
public 'timezone_type' => int 3 | |
public 'timezone' => string 'America/Sao_Paulo' (length=17) | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment