Пример #1
0
function format_data($timestamp, $formato)
{
    global $nomedomes;
    global $nomediasemana;
    nome_do_mes(0);
    switch ($formato) {
        case '?':
            // Faz todas as interações abaixo com output
        // Faz todas as interações abaixo com output
        case 1:
            //         01/02/2001 - 12:00
            $return = date('d/m/Y - H:i', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 2:
            //         01 de fevereiro de 2001
            $return = date('d', $timestamp) . " de " . nome_do_mes(date('m', $timestamp)) . " de " . date('Y', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 3:
            //         01 de fevereiro de 2001 - 12:00
            $return = date('d', $timestamp) . " de " . nome_do_mes(date('m', $timestamp)) . " de " . date('Y', $timestamp) . " - " . date('H:i', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 4:
            //         01 de fevereiro de 2001 às 12h00
            $return = date('d', $timestamp) . " de " . $nomedomes[date('m', $timestamp)] . " de " . date('Y', $timestamp) . " às " . date('H', $timestamp) . 'h' . date('i', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 5:
            //        01/02/2001
            $return = date('d/m/Y', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 6:
            //         Formato bom para o mysql
            //			2002-12-31 14:23:45
            $return = date('Y-m-d H:i:s', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 7:
            //        Domingo, 01 de fevereiro de 2001
            $return = $nomediasemana[date("w", $timestamp)] . ", " . date('d', $timestamp) . " de " . $nomedomes[date('m', $timestamp)] . " de " . date('Y', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 8:
            //        Retorna Timestamp
            $return = $timestamp;
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 9:
            //     dia da semana:   Seg
            $return = substr($nomediasemana[date("w", $timestamp)], 0, 3);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 10:
            //     dia do mês
            $return = date('d', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 11:
            //     dia da semana:   Segunda
            $return = $nomediasemana[date("w", $timestamp)];
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 12:
            //     12h00
            $return = date('H', $timestamp) . 'h' . date('i', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 13:
            //     2001-02-31
            $return = date('Y-m-d', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 14:
            //     Domingo, 21
            $return = $nomediasemana[date("w", $timestamp)] . ', ' . date('d', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 15:
            // 20010231125959
            $return = date('YmdHis', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 16:
            // 20010231
            $return = date('Ymd', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 17:
            // Número de dias no mês
            $return = ultimo_dia_mes(date('m', $timestamp), date('Y', $timestamp));
            //			$return=daysInMonth($timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 18:
            //     Nome do mês
            $return = $nomedomes[date('m', $timestamp)];
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 19:
            //	Dezembro de 2002
            $return = $nomedomes[date('m', $timestamp)] . " de " . date('Y', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 20:
            //	Dia da semana do primeiro dia do mês
            $return = date('w', $timestamp - (date('d', $timestamp) - 1) * 86400);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 21:
            //	Dia da semana do �ltimo dia do mês
            $return = date('w', mktime(0, 0, 0, date('m', $timestamp) + 1, 0, date('Y', $timestamp)));
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 22:
            //	Se a data for dia de semana retorna 1 se for final de semana retorna 0
            if (date("w", $timestamp) == 0 || date("w", $timestamp) == 6) {
                $return = 0;
            } else {
                $return = 1;
            }
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 23:
            //	GMT para meta tag expires
            // Exemplo: '<meta HTTP-EQUIV="Expires" CONTENT="Wed, 26 Mar 2003 23:59:59 GMT">'
            $return = substr(date('r', $timestamp), 0, 25) . ' GMT';
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 24:
            //         Set.1
            $return = ucfirst(substr(nome_do_mes(date('m', $timestamp)), 0, 3)) . '.' . date('d', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 25:
            //         01/02/2001 - 12:00
            $return = date('d/m/Y - H:i:s', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 26:
            //         DD/MM/YYYY HH:MM:SS
            $return = date('d/m/Y H:i:s', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 27:
            //         YYYYMMDDHHMM00 - Usado no Sistema
            $return = date('YmdHis', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 28:
            //  YYYY/MM/DD - Formato para Paths indexados por data
            $return = date('Y/m/d', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 29:
            //  2001
            $return = date('Y', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
        case 30:
            //     12:00
            $return = date('H', $timestamp) . ':' . date('i', $timestamp);
            if ($formato == '?') {
                $formato_out++;
                echo $formato_out . ': ' . $return . '<BR>';
            } else {
                break;
            }
    }
    if ($formato == '?') {
        exit;
    } else {
        if ($return) {
            return $return;
        }
    }
}
				$fecha=$day;
			}
		}
		return $fecha;
	}
	
	function redireccionar($mensaje,$url){
		echo "<SCRIPT LANGUAGE=\"JavaScript\">";
		if($mensaje!=""){ echo "alert('".$mensaje."');"; }
		if($url!=""){ echo "window.location.href = \"".$url."\";"; }
		echo "</script>";
	}
	$mes=date("m");
	$year=date("Y");
	$dia="15";
	$ultimodiadelmes=ultimo_dia_mes($mes,$year);
	
	
	switch(date("d")){
	
		case $dia:
			
			if(!file_exists("planillas/".$dia."_".$mes."_".$year.".txt")){
				escribir_archivo("planillas/".$dia."_".$mes."_".$year.".txt","w","Generado a las ".date("H:i A"));
				redireccionar("","calculos.php?usuario=$usuario&tipo=$tipo&transaccion=store_planilla&redir=1");
			}
			
		break;
	
		case $ultimodiadelmes:
			if(!file_exists("planillas/".$ultimodiadelmes."_".$mes."_".$year.".txt")){