Justin Boxem
Justin Boxem

Reputation: 153

How to insert strings into displayed timestamp?

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.

Upvotes: 0

Views: 53

Answers (2)

wbit
wbit

Reputation: 1

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.

Upvotes: 0

urfusion
urfusion

Reputation: 5501

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";

Upvotes: 2

Related Questions