ylliX - Online Advertising Network

Quick tip – working with dates with ADODb and MSSQL 2000

Yes, it can be really painfull – MSSQL (at least instance I’m using) is saving date in format “d/m/Y H:i:s” but in every part of code I had “Y-m-d H:i:s”. So what now – rewrite everything? Nope, there is ugly but working way to do it, after ADODb object is created and initialized put:

$db->fmtDate = "'d/m/Y'";
$db->fmtTimeStamp = "'d/m/Y H:i:s'";

and that’s it – all dates will be internally converted to given format, so here is full example of config:

define('_ADODB_DIR', '/libs/adodb/'); 
require_once( _ADODB_DIR . 'adodb.inc.php' ); 
$db = &ADONewConnection( 'mssql'); 
$db->Connect( $myServer, $myUser, $myPass, $myDB ); 
$db->fmtDate = "'d/m/Y'";
$db->fmtTimeStamp = "'d/m/Y H:i:s'";

Leave a Reply