Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FREETDS Dateformat issues

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.

like image 685
Naga Avatar asked Jan 29 '26 14:01

Naga


2 Answers

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
like image 125
knb Avatar answered Jan 31 '26 06:01

knb


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.

like image 21
Laughing Vergil Avatar answered Jan 31 '26 05:01

Laughing Vergil