Započni novu temu Odgovori na temu  [ 2 Posta ] 
Autoru Poruka
 Tema posta:
PostPoslato: 04.11.2003. 00:00:00 
Korisnikov avatar

Pridružio se: 24.11.2001. 17:23:58
Postovi: 1619
Lokacija: In the Air
Godina: Dipl.
Smer: IS
Elem, treba mi skripta koja racuna navedeno u opisu teme u odnosu na zadatu vrednost u proslosti. Moze i da se zadaje u samoj skripti a moze da bude i u napred zadata.
Objasnjenje: Onaj fazon kao: "Stari ste 20 godina, 20x12 meseci, X dana i Y sekundi" :p
Ajd ako ima neko neka zakaci na forum, ima picje! ;)


Share on FacebookShare on TwitterShare on Google+
Vrh
 Profil  
Odgovori sa citatom  
 Tema posta:
PostPoslato: 04.11.2003. 02:51:59 
Korisnikov avatar

Pridružio se: 04.11.2001. 23:53:42
Postovi: 571
Lokacija: Уједињене Српске Државе
Mozda ti ovo pomogne, probaj
-----------------------------------------
<?

// 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 >= $base_mon_max)
{
$day_diff = $day_diff - $base_mon_max;
$mon_diff = $mon_diff + 1;
}

// handle overflow of years
if ($mon_diff >= 12)
{
$mon_diff = $mon_diff - 12;
$yr_diff = $yr_diff + 1;
}

// the results are here:

// $yr_diff --> the years between the two dates
// $mon_diff --> the month between the two dates
// $day_diff --> the days between the two dates

// ****************************************************************************

// simple output of the results
print "The difference between <b>".$base_yr."-".$base_mon."-".$base_day."</b> ";
print "and <b>".$current_yr."-".$current_mon."-".$current_day."</b> is:";
print "

";

// this is just to make it look nicer
$years = "years";
$days = "days";
if ($yr_diff == "1") $years = "year";
if ($day_diff == "1") $days = "day";

// here we go
print $yr_diff." ".$years.", ";
print $mon_diff." month and ";
print $day_diff." ".$days;

?>

_________________
Све што сте желели да знате о демократији, а нисте знали кога да питате...


Share on FacebookShare on TwitterShare on Google+
Vrh
 Profil  
Odgovori sa citatom  
Prikaži postove u poslednjih:  Poređaj po  
Započni novu temu Odgovori na temu  [ 2 Posta ] 


Ko je OnLine

Korisnici koji su trenutno na forumu: Nema registrovanih korisnika i 27 gostiju


Ne možete postavljati nove teme u ovom forumu
Ne možete odgovarati na teme u ovom forumu
Ne možete monjati vaše postove u ovom forumu
Ne možete brisati vaše postove u ovom forumu
Ne možete slati prikačene fajlove u ovom forumu

Pronađi:
Idi na:  
cron
Copyleft FONForum 2001-2014 | Powered by phpBB © phpBB Group