Jump to content

Recommended Posts

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 passed
July 10th <-- this is still visible since today is June 29th
July 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";
}

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

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.

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

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.