How to format a date in the MS SQL query using PHP and PDO
Posted on 2011-09-30
Firstly thank you for taking a look at my question.
Essentially I have a query which one of the fields is a date field where it contains the time like below. I want to only pull out the date format like this: 2011-09-01 and do a group by on this field as well.
What it currently comes out like: 2011-09-01 12:38:06.413
I can do a date format on it when I am printing it to the screen and to a csv file, but to do the group by I need it to get rid of the time.
This is my query I am currently using which works, but wanted to add the group by to it.
$query = "SELECT BrandID,DateFunded,RiskLevelID FROM DB Where DateFunded is not NULL and DateFunded between '".$firstmonth."' and '".$today."' order by DateFunded" ;
//Load the query
$stmt = $c->prepare($query) ;
//Run the query
Also how do I add some trouble shooting to the end of the query so I can see any errors that pop up?
Thank you, your assistance is appreciated!