note 75256 added to function.date

From: Date: Sun, 20 May 2007 19:30:57 +0000
Subject: note 75256 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-126776@lists.php.net to get a copy of this message
This is an implementation for days360 formula used in financial calc software, this asumes year with 360 days and months with 30 days. I am looking for a reliable function to add days to a date using 30[E]/360 format. <?php /* Calc days between two dates using the financial calendar 30/360 (usa) or 30E/360(european)<-default $fecha1 and $fecha2 in format: aaaa-mm-dd return days or -1 in case of error. based on cost_analysis.py module Ver. 0.1 public domain, no license required by Harm Kirchhoff */ function days_360($fecha1,$fecha2,$europeo=true) { //try switch dates: min to max if( $fecha1 > $fecha2 ) { $temf = $fecha1; $fecha1 = $fecha2; $fecha2 = $temf; } // get day month year... list($yy1, $mm1, $dd1) = explode('-', $fecha1); list($yy2, $mm2, $dd2) = explode('-', $fecha2); if( $dd1==31) { $dd1 = 30; } //checks according standars: 30E/360 or 30/360. if(!$europeo) { if( ($dd1==30) and ($dd2==31) ) { $dd2=30; } else { if( $dd2==31 ) { $dd2=30; } } } //check for invalid date if( ($dd1<1) or ($dd2<1) or ($dd1>30) or ($dd2>31) or ($mm1<1) or ($mm2<1) or ($mm1>12) or ($mm2>12) or ($yy1>$yy2) ) { return(-1); } if( ($yy1==$yy2) and ($mm1>$mm2) ) { return(-1); } if( ($yy1==$yy2) and ($mm1==$mm2) and ($dd1>$dd2) ) { return(-1); } //Calc $yy = $yy2-$yy1; $mm = $mm2-$mm1; $dd = $dd2-$dd1; return( ($yy*360)+($mm*30)+$dd ); } // usage: echo days_360("2007-01-13","2007-05-20"); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 201.240.25.98 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/75256 Del: integrated -- https://master.php.net/note/delete/75256/integrated Del: useless -- https://master.php.net/note/delete/75256/useless Del: bad code -- https://master.php.net/note/delete/75256/bad+code Del: spam -- https://master.php.net/note/delete/75256/spam Del: non-english -- https://master.php.net/note/delete/75256/non-english Del: in docs -- https://master.php.net/note/delete/75256/in+docs Del: other reasons-- https://master.php.net/note/delete/75256 Reject -- https://master.php.net/note/reject/75256 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126776) next »