Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9213395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:44:21+00:00 2026-06-18T01:44:21+00:00

I am trying to pull the data out from mssql server table to print

  • 0

I am trying to pull the data out from mssql server table to print html table in webpage using php, the data i am pulling down is “DateTime ” column and when i run the script i got error message saying ” Object of class DateTime could not be converted to string “

and the below is my script. can anyone point me correct way? Thank you so much in advance.

$sql = "SELECT  DateCreated FROM Item WHERE Inactive = '0' ";

$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}


while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
   $html_table = '<table border="1" cellspacing="0" cellpadding="2">';
  $html_table .= '<tr><td width="100" align="center">' .$row['DateCreated'].'</td></tr>';

$html_table .= '</table>'; 
echo $html_table;  


}
sqlsrv_free_stmt( $stmt);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:44:22+00:00Added an answer on June 18, 2026 at 1:44 am

    One way to do it would be like this to have the SQL Engine itself return a string value in your first line of code. There might be more performat ways to convert on the PHP end but I’m not as good with that side of the work.

    $sql = "SELECT CONVERT(varchar(10), DateCreated, 101) AS DateCreatedString 
    FROM Item WHERE Inactive = '0' ";
    

    There are a lot of other date format standards you can modify with the third parameter found in this guide from microsoft. The 101 that I used gives the date back in mm/dd/yyyy format, but literally every format under the sun including times, months names, centuries, milliseconds etc. can be returned by using one of the other codes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pull out data from the table I had from the
I'm trying to pull some data out of logs on remote machines using awk,
I'm trying to pull data from the YouTube API into a local MySQL table.
I'm trying to pull in data from a remote SQL Server. I can access
I'm trying to pull some data from a webpage. I have it partially working,
I am trying to pull data from a table I have imported into my
I am trying to pull HTML data out of a WebView . I've seen
I am trying to pull out data from an XML document that seems to
I'm trying to pull a large amount of data out of a WCF web
I'm trying to pull data using a SqlDataReader, one column of which is in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.