note 54067 added to function.time

From: Date: Wed, 22 Jun 2005 21:19:28 +0000
Subject: note 54067 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-90806@lists.php.net to get a copy of this message
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]; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54067 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54067&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54067&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54067&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54067&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54067&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54067&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54067&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90806) next »