FREETDS Dateformat issues

2.1k Views Asked by At

Below SQL statement

SELECT getdate()
go

When I run from SQL Server management studio it gives

"Jul 27 2016 22:00:00.860"

When I run the same from sqsh it gives

"Jul 27 2016 10:00PM"

sqsh uses freetds to connect to SQL server from my linux box. I have a C program which uses freetds and it will work fine when date is retrieved in 24hour format.

I guess there are settings for freetds to get date in required format, can someone please suggest how to accomplish that by freetds settings.

2

There are 2 best solutions below

2
Laughing Vergil On

Currently, the default date format returned by FreeTDS is configured in the locales.conf file. See http://www.freetds.org/userguide/locales.htm for details.

2
knb On

Here's what I just did on my ubuntu linux box:

  1. Type this command at the bash shell: locale My result (shortened): LANG=en_US

  2. Copy locales.conf file to the config directory: sudo cp /usr/share/doc/freetds-common/examples/locales.conf /etc/freetds/

  3. open the /etc/freetds/locales.conf file in an editor

  4. comment out the old date format defined in the locales.conf file (I've used ";" as a comment char), copy the line

  5. Define a date format that you need in the corresponding section of the locales.conf file

    [en_US]

    ;date format = %b %e %Y %I:%M:%S:%z%p

    date format = %Y-%m-%d %H:%M:%S

  6. restart your web server process

Now I get from sqsh:

SELECT getdate();
: 2016-08-01 11:37:45