php 7.4.14 convert smalldatetime to string for html display
-
I'm stumped, and sort of shocked that PHP didn't like the value or type. $sold_date in the the sql server table is defined as smalldatetime. In the table, the value is 2/7/2008 I tried $sold_date->format('m-d-y') and it didn't like it. I also searched and searched, and just found generic anwsers Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in C:\App\Dev\PCAD\project_update.phtml:427 Stack trace: #0 {main} thrown in C:\App\Dev\PCAD\project_update.phtml on line 427
echo "
$sold_date
";
My database call is
$row_proj = sqlsrv_fetch_array($res_proj);
$projectNumber = $row_proj[0];
$proj_stage = $row_proj[1];
$version_no = $row_proj[2];
$customerNumber = $row_proj[3];
$sold_date = $row_proj[4]; // FIXME - convert smalldatetime to string
$sales_no = $row_proj[5];
$swan_job = $row_proj[6];If it ain't broke don't fix it Discover my world at jkirkerx.com
-
I'm stumped, and sort of shocked that PHP didn't like the value or type. $sold_date in the the sql server table is defined as smalldatetime. In the table, the value is 2/7/2008 I tried $sold_date->format('m-d-y') and it didn't like it. I also searched and searched, and just found generic anwsers Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in C:\App\Dev\PCAD\project_update.phtml:427 Stack trace: #0 {main} thrown in C:\App\Dev\PCAD\project_update.phtml on line 427
echo "
$sold_date
";
My database call is
$row_proj = sqlsrv_fetch_array($res_proj);
$projectNumber = $row_proj[0];
$proj_stage = $row_proj[1];
$version_no = $row_proj[2];
$customerNumber = $row_proj[3];
$sold_date = $row_proj[4]; // FIXME - convert smalldatetime to string
$sales_no = $row_proj[5];
$swan_job = $row_proj[6];If it ain't broke don't fix it Discover my world at jkirkerx.com
jkirkerx wrote:
I tried $sold_date->format('m-d-y') and it didn't like it.
How did you try it? I suspect you'd need to use the "complex" syntax[^] to embed that within a string:
echo "
<td class='text-align-center'>
<p class='margin-text-indent'> {$sold_date->format('m-d-y')} </p>
</td>";If that doesn't work, what error do you get?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
jkirkerx wrote:
I tried $sold_date->format('m-d-y') and it didn't like it.
How did you try it? I suspect you'd need to use the "complex" syntax[^] to embed that within a string:
echo "
<td class='text-align-center'>
<p class='margin-text-indent'> {$sold_date->format('m-d-y')} </p>
</td>";If that doesn't work, what error do you get?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Oh that works! I would figured it out eventually, maybe within 3 months ;) Just read the link, did not know that. I was thinking perhaps I had to preprocess that variable before echoing it out to the presentation layer. Well that solves another 500 errors in this project, about 1000 more to go. Thanks Richard, really appreciate the help. This project is really beating me up mentally, but it will be worth it in the end.
If it ain't broke don't fix it Discover my world at jkirkerx.com