zaggs — 2010-02-05T08:07:04-05:00 — #1
I am tryng to show a date which is stored in a MSSQL database (datetime) field (example: 6/1/2010 12:00:00 AM).
Here is the code I am using:
<?=strftime("%d-%m-%Y", strtotime ($row_Recordset1['inceptiondate'])); ?>
The date is always getting displayed like this "31-12-1969" even thoughe the month, day and year are all wrong.
r937 — 2010-02-05T08:36:15-05:00 — #2
sounds like a php problem to me
zaggs — 2010-02-05T09:35:56-05:00 — #3
That's what I originally thought but when I try and echo out the date without any formatting, I get this error:
PHP Catchable fatal error: Object of class DateTime could not be converted to string in E:\\web\\inshorecom0\\htdocs\\submissions.php on line 61
r937 — 2010-02-05T09:37:26-05:00 — #4
still sounds like a php error
zaggs — 2010-02-05T09:45:16-05:00 — #5
Argghh!!! When I echo out the same thing from a MySQL database it works fine but from MSSQL it gives me this. Do I need to change the SQL query?
Here's what im using..
SELECT * FROM submissions where department='".$_GET['sort']."'
r937 — 2010-02-05T09:52:45-05:00 — #6
no, you do not ~need~ to change your query, but i always advise people against using the dreaded, evil "select star" in production applications
let the query return the datetime value as a datetime value, and format it with php
sorry, i can't help you do that, i don't do php and this is the wrong forum
zaggs — 2010-02-05T11:23:10-05:00 — #7
Ok I managed to figure it out using date_format (PHP).
I have another question: The date in the table is in this format: 6/1/2010 12:00:00 AM
How can I write a query to check if the year is 2010?
Thanks in advance.
r937 — 2010-02-05T11:30:23-05:00 — #8
WHERE YEAR(inceptiondate)=2010 is the simplest way of doing it, although it isn't very efficient
an efficient way would be
WHERE inceptiondate >= '2010-01-01'
AND inceptiondate < '2011-01-01'