note 54067 deleted from function.time by betz

From: Date: Wed, 06 Jul 2005 05:53:25 +0000
Subject: note 54067 deleted from function.time by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-91511@lists.php.net to get a copy of this message
Note Submitter: tom at depman dot com ---- Was trying to find a snippet to retrieve an ending date based on start date and term. Could not find one so wrote this. Not 100% accurate but hope this helps someone. <?php $start_date = "2005-01-03"; $term = 36; // number of months $start_date_pieces = split("-",$start_date); $start_sec = mktime(0,0,0, $start_date_pieces[1], $start_date_pieces[2], $start_date_pieces[0]); // months in seconds term(number of months) * 30 days // (in seconds) $term_sec = $term * 2592000; $end_date = date("Y-m-d", $term_sec + $start_sec); // since each month is not always 30 days the end result // gives a different ending day (of the month) // we need to compensate and change the day of the month // to the day the term starts if ( substr($end_date,8,2) != $start_date_pieces[2] ){ $end_date_pieces = split("-",$end_date); $end_date = $end_date_pieces[0]. "-".$end_date_pieces[1]. "-".$start_date_pieces[2]; } ?>

« previous php.notes (#91511) next »