Apply a regex to a variable for time if it contains today's date

Hi :slight_smile:

I am displaying an RSS feed at my Joomla site, and I am trying to alter the timestamp for the feed items if they were posted today.

For those items posted today, I want the timestamp to simply be the hour and minute, e.g. “1:45 pm”

For those items posted on past days, I want the timestamp to be in the format of “Feb. 3”

I am using a Joomla module, which has already modified the timestamp into the format of “Feb. 3, 1:45 pm”. The php variable that displays “Feb. 3, 1:45 pm” is “$feed->itemDate”.

I was thinking it might be good to check whether “$feed->itemDate” contains today’s date, which would be formatted using the date function as “Feb. 3”. If this evaluates to true, then I could use regex to delete the comma and everything before it. If it evaluates to false, then I could delete everything after and including the comma. The problem is, I am not sure this is possible. I wanted to check before I made any futile attempts. Any help would be greatly appreciated.

[php]$feedTimeParts = explode(’, ',$feed->itemDate);
$displayTime = $feedTimeParts[0];
if($feedTimeParts[0] == date(“M. j”))
{
$displayTime = $feedTimeParts[1];
}[/php]

$displayTime should then contain the information you require.

sorry about the delayed thank you - I’ve been swamped and haven’t had time for website learning. Thanks, Smokey PHP. that code worked perfectly for me.

Sponsor our Newsletter | Privacy Policy | Terms of Service