<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Differenza tra due date in anni mesi e giorni]]></title><description><![CDATA[<p dir="auto">Buon giorno a tutti, volevo chiedere se qualcuno potrebbe aiutarmi nella scomposizione della differenza tra due date in un capo che mi ritorna anni mesi e giorni. Vi faccio un esempio: data_assunzione - oggi = il dipendente ad oggi ha 20 anni 10 mesi 4 giorni di servizio.<br />
E' possibile con php? Io per il momento sono riuscito a farlo con access ma con php non ne ho la più pallida idea.<br />
Grazie a tutti<br />
Loris3000</p>
]]></description><link>https://dev.connect.gt/topic/52429/differenza-tra-due-date-in-anni-mesi-e-giorni</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 20:10:30 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/52429.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 Nov 2007 08:41:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Differenza tra due date in anni mesi e giorni on Sat, 22 Dec 2007 08:22:29 GMT]]></title><description><![CDATA[<p dir="auto">Ragazzi ho risolto: ho trovato uno script in rete che fa al caso mio. Ve lo posto così ognuno può adattarlo alle sue esigenze:</p>
<pre><code class="language-php">&lt;?php
// This is a simple script to calculate the difference between two dates
// and express it in years, months and days
// 
// use as in: "my daughter is 4 years, 2 month and 17 days old" ... :-)
//
// Feel free to use this script for whatever you want
// 
// version 0.1 / 2002-10-3
//
// please send comments and feedback to [EMAIL="webmaster@lotekk.net"]webmaster@lotekk.net[/EMAIL]
//
// ****************************************************************************
// configure the base date here
$base_day  = 11;  // no leading "0"
$base_mon  = 5;  // no leading "0"
$base_yr  = 2001;  // use 4 digit years!
// get the current date (today) -- change this if you need a fixed date
$current_day  = date ("j");
$current_mon  = date ("n");
$current_yr  = date ("Y");
// and now .... calculate the difference! :-)
// overflow is always caused by max days of $base_mon
// so we need to know how many days $base_mon had
$base_mon_max  = date ("t",mktime (0,0,0,$base_mon,$base_day,$base_yr));
// days left till the end of that month
$base_day_diff   = $base_mon_max - $base_day;
// month left till end of that year
// substract one to handle overflow correctly
$base_mon_diff   = 12 - $base_mon - 1;
// start on jan 1st of the next year
$start_day  = 1;
$start_mon  = 1;
$start_yr  = $base_yr + 1;
// difference to that 1st of jan
$day_diff = ($current_day - $start_day) + 1;  // add today
$mon_diff = ($current_mon - $start_mon) + 1; // add current month
$yr_diff = ($current_yr - $start_yr);
// and add the rest of $base_yr
$day_diff = $day_diff + $base_day_diff;
$mon_diff = $mon_diff + $base_mon_diff;
// handle overflow of days
if ($day_diff &gt;= $base_mon_max)
{
 $day_diff = $day_diff - $base_mon_max;
 $mon_diff = $mon_diff + 1;
}
// handle overflow of years
if ($mon_diff &gt;= 12)
{
 $mon_diff = $mon_diff - 12;
 $yr_diff = $yr_diff + 1;
}
// the results are here:
 //$yr_diff   --&gt; the years between the two dates
// $mon_diff  --&gt; the month between the two dates
// $day_diff  --&gt; the days between the two dates
// ****************************************************************************
// simple output of the results 
print "La differenza tra &lt;b&gt;".$base_yr."-".$base_mon."-".$base_day."&lt;/b&gt; ";
print "e &lt;b&gt;".$current_yr."-".$current_mon."-".$current_day."&lt;/b&gt; è di:";
print "&lt;br&gt;&lt;br&gt;";
// this is just to make it look nicer
$years = "anni";
$days = "giorni";
if ($yr_diff == "1") $years = "anno";
if ($day_diff == "1") $days = "giorno";
// here we go
print $yr_diff." ".$years.", ";
print $mon_diff." mesi e ";
print $day_diff." ".$days;
?&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/post/631723</link><guid isPermaLink="true">https://dev.connect.gt/post/631723</guid><dc:creator><![CDATA[loris3000]]></dc:creator><pubDate>Sat, 22 Dec 2007 08:22:29 GMT</pubDate></item><item><title><![CDATA[Reply to Differenza tra due date in anni mesi e giorni on Fri, 02 Nov 2007 11:42:44 GMT]]></title><description><![CDATA[<p dir="auto">grazie mille, adesso mi metto all'opera e vediamo se funziona.<br />
a presto</p>
]]></description><link>https://dev.connect.gt/post/631722</link><guid isPermaLink="true">https://dev.connect.gt/post/631722</guid><dc:creator><![CDATA[loris3000]]></dc:creator><pubDate>Fri, 02 Nov 2007 11:42:44 GMT</pubDate></item><item><title><![CDATA[Reply to Differenza tra due date in anni mesi e giorni on Fri, 02 Nov 2007 11:37:11 GMT]]></title><description><![CDATA[<p dir="auto">a me viene in mente solo uan soluzione di queste non so se sia precisa al massimo cmq e un buon inizio penso <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
<pre><code class="language-php">&lt;?php
// la data da cui effettuare il controllo e in formato giorno/mese/anno
list($giorno, $mese, $anno) = explode("/","2/10/2007"); 
// calcolo la differenza tra il timestamp della data definita e la data attuale
// il risultato dovrò dividerlo per 86400 (il numero di secondi in un giorno)
// e arrotondarlo con floor 
$giorni = ((time()-mktime (0,0,0,$mese,$giorno,$anno))/86400);
$anni = floor($giorni/360);
$mesi = floor(($giorni/30)%12);
$giorno =floor($giorni%30);
echo "$anni anni $mesi mesi $giorno giorni";
?&gt;
</code></pre>
<p dir="auto">nello script ho messo una data di un mese indietro purtroppo cosi calcola i mesi tutti composti da 30 giorni non so come ovviare questo problema <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61e.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--disappointed" style="height:1.4em;width:auto;vertical-align:middle" title=":(" alt="😞" /> spero di esserti stato utile comunque <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/customizations/54a3bffb-5e4a-4eb8-81dc-99b2072e5d05-175.gif?v=12b9555a9a1" class="not-responsive emoji emoji-customizations emoji--ciauz" style="height:1.4em;width:auto;vertical-align:middle" title=":ciauz:" alt="" /></p>
]]></description><link>https://dev.connect.gt/post/631729</link><guid isPermaLink="true">https://dev.connect.gt/post/631729</guid><dc:creator><![CDATA[killua85]]></dc:creator><pubDate>Fri, 02 Nov 2007 11:37:11 GMT</pubDate></item></channel></rss>