Zaggs
1
Hi Guys!
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.
Any ideas?
r937
2
sounds like a php problem to me
Zaggs
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
4
still sounds like a php error 
Zaggs
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
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
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
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'