FabioRicali.it

Incrementare o decrementare una data con php

by info@fabioricali.it on mag.08, 2010, under PHP

Questa funzione ci permette di incrementare una data, potendo scegliere tra giorno, mese, anno e relativa formattazione

<?php
function dateInc($date,$intInc,$datePart="day",$format="%Y-%m-%d"){
		return strftime($format, strtotime("$date $intInc $datePart"));
	}
echo "Incremento di un giorno: ".dateInc("2009-05-04",1)."<br/>";
echo "Decremento di 12 giorni: ".dateInc("2009-05-04",-12)."<br/>";
echo "Incremento di un mese: ".dateInc("2009-05-04",1,"month","%d-%m-%Y")."<br/>";
echo "Incremento di un mese formattando la data in italiano: ".dateInc("2009-05-04",1,"month","%d-%m-%Y")."<br/>";
echo "Incremento di un anno: ".dateInc("2009-05-04",1,"year")."<br/>";
?>
:

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...