2

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.

Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
Naga
  • 444
  • 2
  • 7
  • 18

2 Answers2

4

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
knb
  • 9,138
  • 4
  • 58
  • 85
  • Thanks for that, but unfortunately I don't have access to /etc/freetds/, its restricted for my developer login. Any alternative to place the file in <>/freetds/locales.conf and use this directory. – Naga Aug 02 '16 at 15:48
  • 1
    Add point 6.... an apache restart is required! – Oliver M Grech Dec 29 '21 at 12:51
0

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.

Laughing Vergil
  • 3,706
  • 1
  • 14
  • 28
  • hey, I set environment variable LOCALE = <>/locales.conf and modified date format as per my need but still no luck. – Naga Jul 28 '16 at 15:58
  • Corrected link: http://www.freetds.org/userguide/locales.html (edit queue is full, please edit the question when possible and delete this comment) – Ed Avis Jan 17 '22 at 09:19