Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
79 views
in Q2A Core by
edited by

The built-in function qa_when_to_html($timestamp, $fulldatedays) found in /qa-include/app/format.php seems to convert a date into an expression like "some minutes/days ago".

However, I don't seem to use it the correct way.

Let say $time is variable that will retrieve a date in the q2a database. Its raw format is like 2020-08-30 18:10:23.

How should I use qa_when_to_html function?

qa_when_to_html($time, @$options['fulldatedays']) only returns "Array".

qa_when_to_html($time, qa_opt('show_full_date_days')) also returns "Array"!

1 Answer

+2 votes
by
selected by
 
Best answer

If you inspect the return value of qa_when_to_html() (e.g. with print_r()) you'll see that the function indeed returns an associative array. The content should look somewhat like this if the date is less than $fulldatedays ago:

Array
(
    [prefix] =>
    [data] => 4 days
    [suffix] =>  ago
)

or like this if it's more than $fulldatedays ago:

Array
(
    [data] => Aug 20
)

So you need to display it somewhat like this:

$when = qa_when_to_html($time, @$options['fulldatedays']);
echo ($when['prefix'] . $when['data'] . $when['suffix']);

...