0

SITUATION:

I am building a support ticket system where the employee can respond to a ticket. This gets displayed within a sort've chat display, which also includes the time the post was made at.

The date gets stored within a database, and gets saved as a timestamp.

I currently am wondering how I can inject strings inside the retrieved timestamp, since my goal is this:

To display 23-02-2018 09:47:13 as 23-02-2018 {atLabel} 09:47 {$hoursLabel}. In other words this would look in an English version as follows:

23-02-2018 09:47:13 as 23-02-2018 at 09:47 hours

===============================================================

CURRENT DISPLAY:

enter image description here

^ This is achieved by the following Smarty code:

{foreach from=$ticketConversationList item=ticketConversation}
  <div class="holder" style="border-radius: 0;">
    <i class="pull-right">{$ticketHistoryPostedAt}{$ticketConversation.posted_at}</i>
  </div>
{/foreach}

{$ticketHistoryPostedAt} = enter image description here

{$ticketConversation.posted_at} = enter image description here < - This gets fetched using a SQL query on the database, and then the array is send to the foreach using smarty->assign()

NOTICE: This post is not a duplicate of a DATETIME into DD-MM-YYYY HH:MM:SS because my question is specifically about splitting the TIMESTAMP as so I can enter in strings into the display.

Justin Boxem
  • 153
  • 1
  • 3
  • 18
  • 1
    explode on the base of space. – urfusion Feb 28 '18 at 13:38
  • Please refer below: https://stackoverflow.com/questions/14457250/php-splitting-the-date-and-time-within-a-timestamp-value-in-mysql – Raja Tamil Feb 28 '18 at 13:39
  • Possible duplicate of [Mysql: Setup the format of DATETIME to 'DD-MM-YYYY HH:MM:SS' when creating a table](https://stackoverflow.com/questions/8338031/mysql-setup-the-format-of-datetime-to-dd-mm-yyyy-hhmmss-when-creating-a-tab) – Michel Feb 28 '18 at 13:40
  • Just format it when you retrieve it from the database. [Take a look here](https://stackoverflow.com/questions/8338031/mysql-setup-the-format-of-datetime-to-dd-mm-yyyy-hhmmss-when-creating-a-tab) and [here](https://www.w3schools.com/sql/func_mysql_date_format.asp) – Michel Feb 28 '18 at 13:42

2 Answers2

2

You can explode on the base of space then put them together to display in the format you want to

$dateTime = $ticketConversation.posted_at;
$data = explode(" ", $dateTime);
echo $data[0] ." at ".$data[1]." hours";
urfusion
  • 5,528
  • 5
  • 50
  • 87
0

Can't you use something similar as this in template?

{$ticketConversation.posted_at|date_format:%d-%m-%Y}{atLabel}{$ticketConversation.posted_at|date_format:%H:%i}{$hoursLabel}

You might have to convert the retrieved date from DB to DateTime type object.

wbit
  • 1
  • 1