Jump to content

check for date AND time, how


dwest

Recommended Posts

Hi,

I need some help with this code snippet.

It is used with WordPress to allow me to mark blog posts with an expiration date.

Trouble is I also need to be able to specify the time along with the date.

 

Can someone guide me in adding that capability to this snippet?

$expirationdate holds the value of a custom field I add to the blog entry and it currently expects a date formatted as yyyy/mm/dd.

Can I have $expirationdate also hold the time along with the date? Such as yyyy/mm/dd,00:00:00 ? Then I could enter the tag as one entry instead of two separate ones.

 

The code then compares current date to date I've entered and blocks the post from displaying if beyond that date. The addition of time it seems should be fairly easy for a guru (which I'm not).

 

Any help would be appreciated and I'm sure there will be questions I need to answer before any real help can happen. So ask as needed.

 

      ***PUT THIS INSIDE THE WORDPRESS LOOP, FIRST THING***
      <?php //to check against expiration date;
      $currentdate = date("Ymd");
      $expirationdate = get_post_custom_values('expiration');
      if (is_null($expirationdate)) {
      $expirestring = '30005050'; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP;
      } else {
      if (is_array($expirationdate)) {
      $expirestringarray = implode($expirationdate);
      }
      $expirestring = str_replace("/","",$expirestringarray);
      } //else
      if ( $expirestring > $currentdate ) { ?>

      ***THEN PUT THE FOLLOWING LINE AT THE VERY END OF THE WORDPRESS LOOP***
      <?php } //end if for expiration; ?>

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.