GIDForums

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum > PHP Code Library
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Jul-2004, 05:51
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

[function] Calculate Due Dates


Usage:
string calc_due_date( string date, string interval, int add [, string return_date_format] )

returns false on error.

PHP Code:

<?php
/**
 * @name calc_due_date()
 * @created February 21, 2003
 * @author J de Silva
 * @modified July 30, 2004
 * ------------------------------------------------------------------
 */
function calc_due_date( $date, $interval, $add, $return_date_format='Y-m-d' )
{
  $date  =  strtotime( $date );
  if( $date !== -1 )
  {
    $date  =  getdate( $date );
    switch( strtolower($interval) )
    {
      case  'month'  :  $date['mon']  +=  $add;  break;
      case  'day'    :  $date['mday'] +=  $add;  break;
      default        :  $date['year'] +=  $add;
    }
    return( date($return_date_format, mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year'])) );
  }
  return( false );
}
?>


Want to discuss this PHP function? Your comments, corrections, suggestions are welcome here: How to add months to date.
  #2  
Old 30-Jul-2004, 06:00
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Example code using the function: calc_due_dates()


Due Date: 3 months

PHP Code:

<?php
// a sample date...
$date  =  '2004-03-20';

$due_date  =  calc_due_date( $date, 'month', 3 );
echo "<p>Due date for $date is: <b>$due_date</b></p>";
// returns
// <p>Due date for 2004-03-20 is <b>2004-06-20</b></p>
?>

 

Recent GIDBlogNew Corolla Altis, 10th Generation - Part I by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
number of hours between 2 dates gaurav_sting CPP / C++ Forum 2 16-Jun-2004 23:15
[function] Show limited words of a string / text JdS PHP Code Library 0 05-Jun-2003 09:25
[function] BBCodes Collection JdS PHP Code Library 1 26-Jan-2003 09:48
[function] Validate Email Addresses I JdS PHP Code Library 0 23-Jan-2003 03:21
[function] Timer JdS PHP Code Library 0 18-Jan-2003 18:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:22.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.