dateform.php

File Type: php File Location: monofiles/ File name: dateform.php
<?php

    
function date_form($datestr) {

        
$dif time() - (int)$datestr;
        
$day 86400// 1 day
        
        
        
$seconds getdate((int)$datestr);
        
$seconds_curr getdate();
        
        
        
$sp = ($seconds['hours']*3600) + ($seconds['minutes']*60) + $seconds['seconds'];
        
$sc = ($seconds_curr['hours']*3600) + ($seconds_curr['minutes']*60) + $seconds_curr['seconds'];
        
        
        if (
$dif $day) {
            
            
$date 'today';
            
            if (
$dif 28800 ) { // 8h 
            
                
if ($dif 60)
                    
$date 'A few seconds ago';
                
                elseif (
$dif 3600)
                    
$date = ($dif/60 0).'min';
                
                else
                    
$date = ($dif/3600 0).'h';
            
            }
            
            if (
$sp $sc)
                
$date '1d';
        }
        
        else {
        
        
$n=2;
        
        while(
$n <= 29):
            
            if (
$dif $n*$day) {
                
$date = ($n-1).'d';
                
                if (
$sp $sc)
                    
$date $n.'d';    
                
                break;
            }
            
            
$n++;
            endwhile;
        }
        
        
//
        
        
        
        
if (!isset($date)) {
            
            
$m=2;
            
            while(
$m <= 12):
            
                if (
$dif $m*$day*30) {
                    
$date = ($m-1).'m';
                    break;
                }
                
                
$m++;
                endwhile;
        }
        
        if (!isset(
$date)) {    
            
            
$y=1;
            
            while(
$y <= 20):
            
                if (
$dif $y*$day*30*12*2){
                    
$date $y.'y';
                    break;
                }
                
                
$y++;
                endwhile;
        }
        
        
        if (!isset(
$date))
            
$date '...';
            

        return 
$date;
    }

?>