gageorion Posted July 3, 2011 Share Posted July 3, 2011 Hey Guys, I am not a dev, just a designer, so forgive the stupid question...this is rocket science to me, not for you, so thank you! I need to have the date stamp change colors if it is today's date. I have started, but I will not embarrass myself with the slop I have been attempting. Here is what I do have, which simply returns the created date. I want to hi-light todays posts. <span class="moduleItemDateCreated"> <?php echo JHTML::_('date', $item->created, JText::_('<span class="day">%d</span><span class="month">%b</span>')); ?></span> Thanks geniuses. (I am going to school to learn web dev, just not there yet.) Quote Link to comment https://forums.phpfreaks.com/topic/240982-change-css-if-it-is-todays-date/ Share on other sites More sharing options...
mikesta707 Posted July 3, 2011 Share Posted July 3, 2011 What format does that date come in? You can use the php's date function to compare the current date to the date you get from above. check out the date function here: http://php.net/manual/en/function.date.php without knowing the format your function returns though, it would be difficult to give a code example Quote Link to comment https://forums.phpfreaks.com/topic/240982-change-css-if-it-is-todays-date/#findComment-1237809 Share on other sites More sharing options...
gageorion Posted July 3, 2011 Author Share Posted July 3, 2011 Thanks for the response mikesta707! I have included an image of the output. The output WAS in this format Sunday, 26 June 2011 22:59 until I figured out how to use the %d %b to output what you see in the image, a 2 integer date and abbreviated month. Currently there is an external style sheet, but I can just include it in the PHP with if / else statement... just need to get that far. Does that help? Like I said, Im a noob. Thanks! [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/240982-change-css-if-it-is-todays-date/#findComment-1237811 Share on other sites More sharing options...
gageorion Posted July 3, 2011 Author Share Posted July 3, 2011 ADDING TO PREVIOUS POST. I should have learned more before posting... <?php if($params->get('itemDateCreated')): ?> <span class="moduleItemDateCreated"> <?php echo JHTML::_('date', $item->created, JText::_('<span class="day">%d</span><span class="month">%b</span>')); ?></span> <?php endif; ?> By adding this, <?php echo $item->created; ?> i can display the date in this format. 2011-07-03 05:13:29 so $item->created is the date I want to compare to today's date. I will get it eventually. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/240982-change-css-if-it-is-todays-date/#findComment-1237817 Share on other sites More sharing options...
gageorion Posted July 3, 2011 Author Share Posted July 3, 2011 SOLVED MY OWN PROBLEM. For others that may possibly need an answer.... <?php $tdate = date('d M'); $createddate = strtotime($item->created);$cdate=date("d M",$createddate); ?> <?php if($tdate == $cdate): ?> <span class="moduleItemDateCreatedToday"> <?php echo JHTML::_('date', $item->created, JText::_('<span class="day">%d</span><span class="month">%b</span>')); ?></span> <?php else:?> <span class="moduleItemDateCreated"> <?php echo JHTML::_('date', $item->created, JText::_('<span class="day">%d</span><span class="month">%b</span>')); ?></span> <?php endif; ?> $item->created is a date from the database in the format y-m-d h:m:s. I only wanted to compare the day and month, I am using a 'd M' (01 Jul) format. By converting the format of $item->created to the "d M" format, I simply compared the two. Now the current day's posts are highlighted in a different color. May not be a big deal to you code wizards, but i didn't know crap about PHP a few hours ago. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/240982-change-css-if-it-is-todays-date/#findComment-1237855 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.