Jump to content

PHP time (deadline within one week)


kool_samule

Recommended Posts

Hi Chaps,

 

I have a column ['projdue'], which stores the deadline for a project.

I have PHP code and <span class>'s to show projects that are within timescale, due today and overdue:

<?php 
      // get the date parts from the MySQL date
      $dateparts = preg_split('/[-\s]/', $row_rsProjects['projdue']);
      // get the Unix timestamp for midnight at the beginning of the due date
      $projdue = mktime(0,0,0, $dateparts[1], $dateparts[2], $dateparts[0]);
      // get the Unix timestamp for midnight at the beginning of today
      $today = mktime(0,0,0, date('n'), date('j'), date('Y'));
      if ($today == $projdue) { ?>
      <tr class="duetoday">
        <?php } else if ($today > $projdue) { ?>
        <tr class="within">
          <?php } else if ($today < $projdue) { ?>
        <tr class="overdue">
          <?php }?>

What I'm after is a bit of code to flag-up any projects that are due in 7 days

Link to comment
https://forums.phpfreaks.com/topic/185877-php-time-deadline-within-one-week/
Share on other sites

I use unix timestamps to do this.

 

Save the current time() in a variable called $cTime;

Get 7 days ahead by adding 7 days of seconds to $cTime and store in $dTime;

then get the current project Due time $pTime;

 

(all of these should be unix timestamps).

 

Then it's easy:

 

if($pTime < $dTime){

  echo("Less than 7 days remaining");

}else{

  continue;

}

 

so if the Project due timestamp, is less (sooner) than the current time+7 days, then it should be flagged.

 

Hope this Helps,

-CB-

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.