dwest Posted February 18, 2008 Share Posted February 18, 2008 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/91650-check-for-date-and-time-how/ Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/91650-check-for-date-and-time-how/#findComment-469411 Share on other sites More sharing options...
dwest Posted February 18, 2008 Author Share Posted February 18, 2008 Excellent! Thanks I'll give that a try. Quote Link to comment https://forums.phpfreaks.com/topic/91650-check-for-date-and-time-how/#findComment-469422 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.