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

Guys I wanna add a "NEW!" picture to questions which are not older than 3 days.. So I thought if I can retrieve data like the day of the month when a question was asked, I can compare it to the day of today and do things with it,

So my question is:

how I can get the day of the month when a question is created?

Is there something like #question['date']['day'] which I can use ?

1 Answer

+2 votes
by
edited by
 
Best answer

The created date is stored as a unix timestamp, which is an integer.  Use php's date() function to get the parts of the date from it:

                $created = $question['raw']['created'];
                $day = date('j',$created);
                $month = date('n',$created);

You can also use:

qa_time_to_string(qa_opt('db_time')-$created);

to get the age of the post.  This will return a string like

6 days

for a post six days old.

Edited to use $question as per the original question's requirements - for access higher up in the hierarchy, use either $this->content['q_view']['raw']['created'] or $this->content['q_list']['qs'][$index]['raw']['created'] as required.

by
edited by
thanks a million Noah!
by

Noah, when I add that code to function q_item_main($question) in qa-theme.php it gives me errors...

Notice: Undefined index: q_view

sad

by
If you put it at q_item_main, you may not have q_view, and even when you do, it won't correspond to the q_item indexed as $question.  Use $question['raw']['created'] instead.
by
yw.  just make sure you share your code as a plugin when it's done ;)
...