Last active
August 29, 2015 14:12
-
-
Save OjosAlertaAC/681bc71ec3dbdc5bd755 to your computer and use it in GitHub Desktop.
mssql SmallDateTime to mysql datetime
This file contains 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
/* Alfonso Orozco Aguilar for Ojos Alerta AC - ojosalerta.org | |
Using LGPL 2.0 Exclusively | |
https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html | |
Original version: 02/jan/2015 | |
Comments to : github(nospam)@alfonsoorozco.com | |
The purpose of this snippet is convert the smalldatetime of a mssql server to mysql datetime | |
*/ | |
function fixsmalldatetime($origin){ | |
// receive a '21 Jul 2010 11:44AM' and convert to '2010-07-21 11:44:00' | |
// because multiple causes we can have diff letters in the string of the time | |
// we need convert time to timestamp and timestamp to date time, | |
// leave extra for legibility, edit second one for your country month locale | |
$origin=strtolower($origin); // normalize to lower case | |
// init if your month is not in english,. convert to english | |
$origin =str_replace('ene','jan',$origin); | |
//$origin =str_replace('feb','feb',$origin); | |
//$origin =str_replace('mar','mar',$origin); | |
$origin =str_replace('abr','apr',$origin); | |
//$origin =str_replace('may','may',$origin); | |
//$origin =str_replace('jun','jun',$origin); | |
//$origin =str_replace('jul','jul',$origin); | |
$origin =str_replace('ago','aug',$origin); | |
//$origin =str_replace('sep','sep',$origin); | |
//$origin =str_replace('oct','oct',$origin); | |
//$origin =str_replace('nov','nov',$origin); | |
$origin =str_replace('dic','dec',$origin); | |
// end if your month is not in english,. convert to english | |
$final =strtotime($origin); // convert to timestamp | |
$final=date('Y-m-d H:i:s',$final); // timestamp to date | |
return $final; | |
} // fix smalldatetime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment