listerdl Posted June 30, 2013 Share Posted June 30, 2013 Hi, this is what I am trying to do:I have to make an enrollment form for a course.I'd like it so that when a date expires it 'dies' and is removed whilst the next date that hasn't come is still 'alive' and when that day comes it 'dies' and so on...So the page would look like this:<< ENROLL BUTTON >>June 10th <--- this would have disappeared from view since that day/ date has passedJuly 10th <-- this is still visible since today is June 29thJuly 15th <-- this is still visible<< ENROLL BUTTON >>I am thinking that when a 'timestamp' variable has expired in just dissapears - but this doesn't work when I tested the below. I think I am missing something very basic - all help very gratefully received! <?php //1. Set the timezone date_default_timezone_set('America/New York'); //2. define the current timestamp $current_timestamp = time(); //3. Define the expiry timestamp $expiry_timestamp1 = mktime(22, 33, 11, 6, 29, 2013); // mktime(hr,mins,sec,mth,day,yr) $expiry_timestamp2 = mktime(23, 34, 11, 6, 29, 2013); // mktime(hr,mins,sec,mth,day,yr) $expiry_timestamp3 = mktime(23, 35, 11, 6, 29, 2013); // mktime(hr,mins,sec,mth,day,yr) if($current_timestamp < $expiry_timestamp1) { // insert content here that you want showing as long as the current_timestamp is less than the expiry_timestamp. echo "This is within the deadline 1"; } if($current_timestamp < $expiry_timestamp2) { // insert content here that you want showing as long as the current_timestamp is less than the expiry_timestamp. echo "This is within the deadline 2"; } if($current_timestamp < $expiry_timestamp3) { // insert content here that you want showing as long as the current_timestamp is less than the expiry_timestamp. echo "This is within the deadline 3"; } // insert a message which shows that the content is now hidden. else { echo "This is not"; } Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 30, 2013 Share Posted June 30, 2013 What exactly is "It" that dies/goes away? Something on a page? Something in a table? What is "it"? Quote Link to comment Share on other sites More sharing options...
listerdl Posted June 30, 2013 Author Share Posted June 30, 2013 Thanks -By "it" I just mean the date.... So the page would say:"These are the dates of the course" March 10th 2013 June 10th 2013 July 10th 2013 August 10th 2013 * By dies/ goes away - I mean the dates that are no longer applicable, i.e. that date has gone, it's in the past, so in the above example March and June would NOT be on the page... That's it!you reckon I am close with my snippet above? thanks for your help btw Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 30, 2013 Share Posted June 30, 2013 I don't know what you are doing. You want to "not display" a past date. What's the difficulty with that? Quote Link to comment Share on other sites More sharing options...
listerdl Posted June 30, 2013 Author Share Posted June 30, 2013 You want to "not display" a past date. What's the difficulty with that? I am new to php hence my "difficulty" is that I don't know how to "not display a past date" - hence me reaching out to the forum. Thanks all the same. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 30, 2013 Share Posted June 30, 2013 Get the current date/time. When you are building your output, compare the date/time value you are thinking of outputting to the current d/t. If it is what you want to show, then show it. And repeat with the next date/time value you have. No? So now you need to learn some php. The manual has plenty of info on managing dates and datetimes. Quote Link to comment Share on other sites More sharing options...
listerdl Posted June 30, 2013 Author Share Posted June 30, 2013 Great - this works! <?php $end_date = strtotime('12:00am June 8, 2013'); $now = time(); if ($end_date < $now) { ?> <!--<p></p>--> <?php } else { ?> <p class="lead">July 8th - 12th 2013</p> <?php } ?> Works fine! Does it look ok to you - is there anything depreciated here? I guess the time comes from MY server right? Thanks Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 1, 2013 Share Posted July 1, 2013 Looks confusing but apparently it looks better to you. You'll get it. Quote Link to comment Share on other sites More sharing options...
listerdl Posted July 1, 2013 Author Share Posted July 1, 2013 It works! I guess that's the key thing - Ill probably laugh at it in a few months time when I am a PHP Guru/ Expert Thanks for looking in though! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 1, 2013 Share Posted July 1, 2013 HTH in giving a kick-start. Be sure to mark this answered. Quote Link to comment 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.