# PHP, MSSQL, Date Select

**URL:** <https://www.phphelp.com/t/php-mssql-date-select/29702>\
**Category:** General Database (Oracle, SQL Server, etc)\
**Created:** [August 14, 2019, 7:38pm UTC](https://www.phphelp.com/t/php-mssql-date-select/29702 "2019-08-14T19:38:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreams3577](https://www.phphelp.com/letter_avatar_proxy/v4/letter/d/d07c76/32.png) [@dreams3577](https://www.phphelp.com/u/dreams3577)\
**Post date:** [August 14, 2019, 7:38pm UTC](https://www.phphelp.com/t/php-mssql-date-select/29702/1 "2019-08-14T19:38:05Z")

</div>

Hi All  
I am trying to echo a date held within a MSSQL Table,  
the date is being stored as “2019-08-15 16:00:00.000”

Table Columns  
id, Expected  
4272, 2019-08-15 16:00:00.000

if I run the below select query in SQL Studio manager it works  
`SELECT Expected FROM [visitor].[dbo].[Visits] WHERE id = 4272;`

however running the below in a php web page causes a blank page

> ```
> $sql = "SELECT Expected FROM [visitor].[dbo].[Visits] WHERE id = 4272";
> $stmt = sqlsrv_query( $conn, $sql );
> while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
> echo "<tr><td>".$row['Expected']."</td></tr>";
> }
> 
> ```

IE php will not let me echo the date as it is held within the MSSQL database..

Any thoughts?  
Many Thanks  
Steve

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [August 14, 2019, 10:40pm UTC](https://www.phphelp.com/t/php-mssql-date-select/29702/2 "2019-08-14T22:40:56Z")

</div>

There are multiple reasons you might be getting a blank page.

To start, what does the ‘view source’ of the blank page show?

Next, is php’s error\_reporting set to E\_ALL and display errors set to ON, in the php.ini on your system so that php will report and display **all** errors? For a parse/syntax error, you cannot put these settings into your code since your code never runs to cause the settings to take effect.

Does your code have error handling for the database connection (it has none for the query), so that you would know if the database statements are failing?

Is the posted code actually inside a html table so that the tr/td markup would cause a row to be displayed where you think it should?

---

<div class="post-metadata">

**Author:** ![dreams3577](https://www.phphelp.com/letter_avatar_proxy/v4/letter/d/d07c76/32.png) [@dreams3577](https://www.phphelp.com/u/dreams3577)\
**Post date:** [August 15, 2019, 12:46am UTC](https://www.phphelp.com/t/php-mssql-date-select/29702/3 "2019-08-15T00:46:32Z")

</div>

Hi… thanks for your help

All other echo statements work and therefore i know that the mssql connection and table tags are ok.

I think it is just the way that the data needs to be echo’d due to it being a mssql datetime, I haven’t however got all your suggested php error display settings turned on…

I’ll give that a try

---

<div class="post-metadata">

**Author:** ![chorn](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/b5ac83/32.png) [@chorn](https://www.phphelp.com/u/chorn)\
**Post date:** [August 15, 2019, 6:46am UTC](https://www.phphelp.com/t/php-mssql-date-select/29702/4 "2019-08-15T06:46:20Z")

</div>

I personally don’t have an experience with connecting to MSSQL from PHP, but i would give PDO a try, so you may get better error messages like:

```auto
$pdo = new PDO('MSSQL_CONNECTION_STRING', 'username', 'password', array(
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));

```
