Afficher un message
Vieux 19/02/2008, 12h40   #5
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Different MSSQL output date format from the same PHP script

Alessandro wrote:
> On 19 Feb, 10:55, Toby A Inkster <usenet200...@tobyinkster.co.uk>
> wrote:
>> Alessandro wrote:
>>> I have a Windows Server 2003 R2 SP2 box where MS SQL 2000 SP4 is
>>> running.

>> Using MSSQL, you are really best off specifying your desired date format
>> as part of the query itself. e.g.
>>
>> SELECT CONVERT(varchar(20),my_date,20) AS my_date
>> FROM my_table

>
> I agree with you approach. Unfortunately I have many queries of this
> kind:
>
> SELECT * FROM my_table
>
> and I display datetime columns with instructions like the following:
> echo "DATE1: ".date("d/m/Y",strtotime($row[DateTimeColumn1]));
>
> I have to parse all my scripts (too many) and change both the query
> and the echo argument...
>


SELECT * is not a good thing to use. You are much better off always
specifying the columns.

For one thing, it's very seldom you need all of the columns. But more
importantly, what happens if someone later adds a new column to the
table (i.e. a 5mb BLOB)?

Also, if someone later deletes or renames a current column, the query
will fail, making the problem very obvious. Otherwise you may not even
get an error message, depending on your error settings - just incorrect
output, which may or may not be noticed for a while.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
 
Page generated in 0,05150 seconds with 9 queries