Categories > TinyButStrong general >

Time format: seconds are not displayed from MSSQL

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: bunak
Date: 2006-10-27
Time: 08:35

Time format: seconds are not displayed from MSSQL

Hi, I don't know where is problem, but when I connect to MSSQL server and I try get a date which is defined as datetime, when I set frm='yyyy-mm-dd hh:nn:ss' I'll get time without seconds. Only :00 is displayed.
But wwhen I run same SQL question in Enterprice architect, I'll get correct format with seconds and miliseconds.
By: bunak
Date: 2006-10-27
Time: 09:40

Re: Time format: seconds are not displayed from MSSQL

Sorry i found problem in PHP. You must set
ini_set('mssql.datetimeconvert',false);
for connection with MSSQL server.
By: Skrol29
Date: 2006-10-27
Time: 10:18

Re: Time format: seconds are not displayed from MSSQL

Hi,

A DateTime value in MySQL is retrurned as a string in PHP with the following format :
Using the mssql library : "2006-10-27 09:46:09.210"
Using the odbc library : "27/oct./2006 9:51" (french configuration)

For a SmallDateTime value,
the mssql library returns : "2006-10-27 09:46:09"

The problem is that PHP may not convert such strings as expected (TBS uses strtotime() for parameter "frm").
The solution I have found for my work is to use CONVERT() in my SQL statement when I need to display dates.
SELECT CONVERT(VarChar(19),MyDate,120) AS DateX
It returns a string like "2006-10-27 09:46:09" which is always good for PHP.
I also use
CONVERT(VarChar(10),MyDate,112) AS DateX
It returns a string like "20061027" which is always good for both PHP and MySQL.