Jump to content

Change CSS if it is todays date...


gageorion

Recommended Posts

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.)

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.