Showing date from MSSQL row

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("&#37;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?

sounds like a php problem to me

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 

still sounds like a php error :slight_smile:

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']."'

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

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. :slight_smile:

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'