473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Weird dates from mssql (4.2.3 / 4.4.0-3)

Hi

SQL Server 2000 Database:

Table: Thing
Columns: id (int), nameOfThing (int), dateOfThing (datetime)

I put some data in it:

1, dave, 9/11/1973 14:33:22
2, bill, 12/6/1980 13:23:33

Then I run a query from PHP4.4.0-3 (on Ubuntu) from Apache2.

<?php
$db_server = "192.168.1.123";
$model_connection = mssql_connect ($db_server, "user", "password");
mssql_select_db ("davetest", $model_connection);
$sql = "select dateOfThing from Thing where id = 1";
$result = mssql_query($sql, $model_connection);
$myarray = mssql_fetch_row ($result);
print_r($myarray);
?>

Result is this:

Array ( [0] => Tue Sep 11 00:00:00 1973 )

When I really want: 9/11/1973 14:33:22

I thought I'd fixxed it with the php.ini line:

mssql.datetimeconvert = Off

However it still returns the same 'converted' datetime.

I have restarted Apache and restarted the machine. I have made sure
this is the correct php.ini file I'm editing too.

Summary

On our production box which is running PHP4.2.3 I get:

PHP4.2.3 - Sep 11 1973 2:33PM (notice it is even chopping off seconds)

PHP4.4.0-3 - Tue Sep 11 14:33:22 1973

How to turn off this date conversion / formatting?

Cheers

Dave.

Feb 16 '06 #1
4 1494
More info:

sajuks on experts-exchange.com kindly suggested:

echo date("m/d/Y h:i:s", strtotime($row['dateOfThing']))."<br>";

which wil work.. however we've got a lot of legacy code which will need
fixxing (groan).. so I'd rather try and get the dates coming from the
database/driver in the old way.

Cheers.

Dave.

Feb 16 '06 #2
On Thu, 16 Feb 2006 13:24:30 -0800, davemateer wrote:
How to turn off this date conversion / formatting?


Get Oracle.

--
http://www.mgogala.com

Feb 17 '06 #3
>From the manual...
The DATETIME type is used when you need values that contain both date
and time information. MySQL retrieves and displays DATETIME values in
'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01
00:00:00' to '9999-12-31 23:59:59'.
From the result, it appears you are not entering the correct format.

Instead of 9/11/1973 14:33:22
enter '1973-09-11 14:33:22'

You can format your date within your qry like this
SELECT DATE_FORMAT(dateOfThing , '%Y - %m %d ') ...;
-> '2006-01-21'

Or use php to format the result
$formatted_date = date("Y-m-d",strtotime($myarray['dateOfThing']));
-> '2006-01-21'

http://dev.mysql.com/doc/refman/5.0/...functions.html
http://us3.php.net/manual/en/function.date.php

Feb 17 '06 #4
Thanks for the replies (getting Oracle would be nice...however MSSQL is
really quite good).

On that note cruicalmoment, I'm doing everying in Microsoft SQL Server
2000, and not MySQL... but thanks for the reply.

All the best

Dave.

Feb 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: mj | last post by:
Hello, thanks for the help. I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm firewall) Apache 2.0.52 MySQL 4.1.7 PHP 5.1.0-dev I have developed a PHP/MySQL web app that...
4
by: Russell | last post by:
I'm having a fit with a query for a range of dates. The dates are being returned from a view. The table/field that they are being selected from stores them as varchar and that same field also...
3
by: Matt | last post by:
Hello, I have a query that I would like to schedule in DTS. The criteria of this query checks for records in the table that are within the current quarter. Here is what I have. WHERE...
2
by: andybriggs | last post by:
An Access 97 database is running quite happily on about 30 IBM ThinkPads. Some of the users, however, have now installed some components of Office 2000 like Word and Excel. On those machines, the...
1
by: Alicia | last post by:
I basically wanted something that would do a count of the dates, then group them by their week name.. BEFORE: Resource Date Total number of times that date Appeared (Count) 4/3/03 ...
14
by: Kukurydz | last post by:
I've got such problem: My database is stored on MSSQL Server. I have to write reports for it in MSAccess. I've got a problem with creating a query which will select records from MSSQL table with...
2
by: Ian Hinson | last post by:
Hi, Sometimes I find it handy to construct an sql string for action queries, and then run it directly against the database and/or connection instead of using Recordsets for simple updates. eg....
2
by: jblankenburg | last post by:
Please help! I am hunting high and low for an equivalent function for MSSQL's DATENAME function. Here's the spec on the function from MSSQL's Books Online: DATENAME Returns a character...
2
by: akronymn | last post by:
I have an mssql database that I need to migrate to mysql. For some reason though any queries to any columns of type datetime are returned in French in the following format: 7/avr/2004 14:00 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.