Usingthe following shortcode function, I have the code building a table by querying the DB. That all works fine. BUT when I add any type of formatting to the TimeStamp
column such as DATE_FORMAT or TIME the output for that column only goes blank. No errors are in the console to look at. I am trying to extract only the time and put it in a 12 hour format instead of the typical TIMESTAMP format of date and time in the 24hr set up.
Is there a conflict with some of the PHP that causes it not to display the timestamp?
function test2() {
global $wpdb;
$results = $wpdb->get_results("SELECT `name`, `partysize`, `phonenumber`, `emailaddress`, DATE_FORMAT(`Time_stamp`, '%h %i' ), `Wait`, `currentstatus` FROM mytablename m RIGHT JOIN (SELECT wdt_ID, CONCAT(ROUND(Time_to_sec(TIMEDIFF (NOW() ,`Time_stamp`))/60,0), ' Min') AS Wait FROM mytablename) as t on m.wdt_ID = t.wdt_ID WHERE Time_stamp >= date_sub(now(),interval 3 hour) ");
if(!empty($results))
{
echo "<table width='100%' border='0' style='display:inline-table'>
<th>Name</th>
<th>Party Size</th>
<th>Phone Number</th>
<th>Email Address</th>
<th>Time Stamp</th>
<th>Status</th>
<th>Wait</th>
<th>Action</th> ";
echo "<tbody>";
foreach($results as $row){
echo "<tr>";
//echo "<td>" . $row->wdt_ID . "</td>";
echo "<td>" . $row->name . "</td>";
echo "<td>" . $row->partysize . "</td>";
echo "<td>" . $row->phonenumber . "</td>";
echo "<td>" . $row->emailaddress . "</td>";
echo "<td>" . $row->Time_stamp . "</td>";
echo "<td id='tdid_".$row->wdt_ID."'>" . $row->currentstatus . "</td>";
echo "<td>" . $row->Wait . "</td>";
echo '<td> <a href="javascript:void(0)" class="button seated-btn" onclick="seatclick('.$row->wdt_ID.')" data-id="'.$row->wdt_ID.'"></a></td>';
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
}
}
add_shortcode('test2', 'test2');
EDIT 1 As per Eric7777777 I have added the print and its output is below when using just the Time_stamp:
Array
(
[0] => stdClass Object
(
[wdt_ID] => 9
[name] => test2
[partysize] => 3
[phonenumber] => 465
[emailaddress] => dis@doc.com
[Time_stamp] => 2020-09-24 19:02:47
[currentstatus] => Waiting
[Wait] => 138 Min
)
)
and with the DATE_FORMAT(Time_stamp:
Array
(
[0] => stdClass Object
(
[DATE_FORMAT(Time_stamp, '%h %i %p')] => 07 02 PM
)
)