Re: Different MSSQL output date format from the same PHP script



Alessandro wrote:
On 19 Feb, 10:55, Toby A Inkster <usenet200...@xxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxx
==================

.



Relevant Pages

  • Re: Are Linq-SQL methods commutative
    ... because to translate what is being done in LINQ to ... of the previous query. ... the intention of the linq query with SQL. ... get 2 different resultsets by specifying them in a different order, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Numeric Field Overflow
    ... Change the format of any total field from what to what? ... your query please. ... If I then open it in design view and change the format of any total ... Then the error message will occur again. ...
    (comp.databases.ms-access)
  • Re: "Select" & "Order By" OK- WHERE Doesnt Work !
    ... The error message was "could not execute query". ... format' 'artist'. ...
    (comp.lang.php)
  • Re: problem with IWbemService.ExecNotificationQuery()
    ... semi-sync by specifying 'return immediately' is just as performant in nearly ... regular ExecQuery is required to get non-event informational WMI objects. ... >>> Notification or Asyn.Notification query. ... >>> an event query results in a request to poll all objects in a namespace. ...
    (microsoft.public.win32.programmer.wmi)
  • Re: This Expression is typed incorrectly, or it is too complex to be evaluated
    ... Note that the format makes no difference - ... "SQL Queries for Mere Mortals" ... > information from the second query and groups, ... and then it gives me the "Complex" error message. ...
    (microsoft.public.access.queries)