Foros del Web » Programando para Internet » PHP »

POST Funciones FECHA(Resueltos)

Estas en el tema de POST Funciones FECHA(Resueltos) en el foro de PHP en Foros del Web. Bueno pues decidi a hacer este POST para los que tengan problemas con las fecha, aqui estare publicando codigos que puedan servir Por mientras les ...
  #1 (permalink)  
Antiguo 15/08/2007, 09:14
 
Fecha de Ingreso: noviembre-2005
Ubicación: Torreon Coahuila
Mensajes: 100
Antigüedad: 18 años, 5 meses
Puntos: 1
POST Funciones FECHA(Resueltos)

Bueno pues decidi a hacer este POST para los que tengan problemas con las fecha, aqui estare publicando codigos que puedan servir


Por mientras les dejo estas 2


Código PHP:

$clasificacion
=$_POST['sel'];
switch(
$clasificacion)
         {
    case 
1:
                
$fechatime() + (24 60 60);
                echo 
date("d/m/Y"$fecha);
     break;
    case 
2:
                
$fechatime() + (24 60 60);
                echo 
date("d/m/Y"$fecha);
     break;
    case 
3:
                
$fechatime() + (24 60 60);
                echo 
date("d/m/Y"$fecha);
     break;
    case 
4:
                
$fechatime() + (424 60 60);
                echo 
date("d/m/Y"$fecha);
     break;
    case 
5:
                
$fechatime() + (524 60 60);
                echo 
date("d/m/Y"$fecha);
     break;
    case 
6:
                
$fechatime() + (624 60 60);
                echo 
date("d/m/Y"$fecha);
     break;
     case 
7:
                
$fechatime() + (724 60 60);
                echo 
date("d/m/Y"$fecha);
     break;
     case 
8:
                
$fechatime() + (8 24 60 60);
                echo 
date("d/m/Y"$fecha);
     break;
     default:
                
$fechatime() + (024 60 60);
                echo 
date("d/m/Y"$fecha);
     break;
         
        }
?> 
Aqui dependiente del valor de $clasificacion te suma ya sea 1,2,3 etc. dias
a la fecha actual


Código PHP:
<?php
//The function returns the no. of business days between two dates and it skeeps the holidays
function getWorkingDays($startDate,$endDate,$holidays){
    
//The total number of days between the two dates. We compute the no. of seconds and divide it to 60*60*24
    //We add one to inlude both dates in the interval.
    
$days = (strtotime($endDate) - strtotime($startDate)) / 86400 1;

    
$no_full_weeks floor($days 7);
    
$no_remaining_days fmod($days7);

    
//It will return 1 if it's Monday,.. ,7 for Sunday
    
$the_first_day_of_week date("N",strtotime($startDate));
    
$the_last_day_of_week date("N",strtotime($endDate));

    
//The two can't be equal because the $no_remaining_days (the interval between $the_first_day_of_week and $the_last_day_of_week) is at most 6
    //In the first case the whole interval is within a week, in the second case the interval falls in two weeks.
    
if ($the_first_day_of_week $the_last_day_of_week){
        if (
$the_first_day_of_week <= && <= $the_last_day_of_week$no_remaining_days--;
        if (
$the_first_day_of_week <= && <= $the_last_day_of_week$no_remaining_days--;
    }
    else{
        if (
$the_first_day_of_week <= 6$no_remaining_days--;
        
//In the case when the interval falls in two weeks, there will be a Sunday for sure
        
$no_remaining_days--;
    }

    
//The no. of business days is: (number of weeks between the two dates) * (5 working days) + the remainder
    
$workingDays $no_full_weeks $no_remaining_days;

    
//We subtract the holidays
    
foreach($holidays as $holiday){
        
$time_stamp=strtotime($holiday);
        
//If the holiday doesn't fall in weekend
        
if (strtotime($startDate) <= $time_stamp && $time_stamp <= strtotime($endDate) && date("N",$time_stamp) != && date("N",$time_stamp) != 7)
            
$workingDays--;
    }

    return 
$workingDays;
}

//Example:

$holidays=array("2006-12-25","2006-12-26","2007-01-01");

echo 
getWorkingDays("2007-08-01","2007-08-31",$holidays)
// => will return 8
?>
Este script te devuelve el total de dias que han pasado entre las 2 fechas, y puedes agregarle los dias festivos que quieres como parametros ok


Si mejoran los scripts los publican porfavor para todos aprender
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:19.