[Dbix-class] InflateColumn DateTime tricks with MSSQL/Microsoft_SQL_Server

Christopher H. Laco claco at chrislaco.com
Tue Jan 15 19:49:46 GMT 2008


Michael Higgins wrote:
> On Tue, 15 Jan 2008 10:24:38 -0800
> Marc Mims <marc at questright.com> wrote:
> =

>> Until we know whether MSSQL *always* returns dates in this fromat via
>> ODBC, or it is a local configuration issue, we shouldn't commit that
>> change to DBI::ODBC::Microsoft_SQL_Server.  Hopefully, you can provide
>> some detail on that?
> =

> They do not.
> =

> On the linux side (FreeTDS, unixODBC) it returns 2008-01-14 00:00:00.000
> =

> On the native side, it returns 2008-01-14 00:00:00 :(
> =

> Cheers,
> =


But there is hope. From Yee Olde Books Online.
You can change the date format in an on_connect_do for MSSQL:

> SET DATEFORMAT
> Sets the order of the dateparts (month/day/year) for entering datetime or=
 smalldatetime data. =

> =

> Syntax
> SET DATEFORMAT { format | @format_var } =

> =

> Arguments
> format | @format_var
> =

> Is the order of the dateparts. Can be either Unicode or DBCS converted to=
 Unicode. Valid parameters include mdy, dmy, ymd, ydm, myd, and dym. The U.=
S. English default is mdy.
> =

> Remarks
> This setting is used only in the interpretation of character strings as t=
hey are converted to date values. It has no effect on the display of date v=
alues.
> =

> The setting of SET DATEFORMAT is set at execute or run time and not at pa=
rse time.
> =

> Permissions
> SET DATEFORMAT permissions default to all users.
> =

> Examples
> This example uses different date formats to handle date strings in differ=
ent formats.
> =

> SET DATEFORMAT mdy
> GO
> DECLARE @datevar datetime
> SET @datevar =3D '12/31/98'
> SELECT @datevar
> GO
> =

> SET DATEFORMAT ydm
> GO
> DECLARE @datevar datetime
> SET @datevar =3D '98/31/12'
> SELECT @datevar
> GO
> =

> SET DATEFORMAT ymd
> GO
> DECLARE @datevar datetime
> SET @datevar =3D '98/12/31'
> SELECT @datevar
> GO
> =



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080115/ac=
5fe5e7/signature.pgp


More information about the DBIx-Class mailing list