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
https://forums.phpfreaks.com/topic/91650-check-for-date-and-time-how/
Share on other sites

i would suggest using unix timestamp instead of a formatted date. that way you can have second accuracy. it would fit in one field and take up less space.

 

to get unix timestamp use time();

--

 

see  http://uk3.php.net/time for examples

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.