Skip to content

Instantly share code, notes, and snippets.

@xthiago
Created August 13, 2013 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xthiago/6224996 to your computer and use it in GitHub Desktop.
Save xthiago/6224996 to your computer and use it in GitHub Desktop.
Transformar Datetime do SQL SERVER em DateTime do PHP
<?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