Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

Incremento de fecha tomando dias hábiles

Estas en el tema de Incremento de fecha tomando dias hábiles en el foro de SQL Server en Foros del Web. Hola a todos quiero saber Porfa cómo incremento una fecha tomando encuenta solamente días hábiles??? Tengo un SP y estoy usando un dateadd(Day,@duracion,@fec_inicio); Pero por ...
  #1 (permalink)  
Antiguo 18/01/2006, 13:15
 
Fecha de Ingreso: enero-2006
Mensajes: 11
Antigüedad: 18 años, 3 meses
Puntos: 0
Exclamación Incremento de fecha tomando dias hábiles

Hola a todos quiero saber Porfa cómo incremento una fecha tomando encuenta solamente días hábiles???

Tengo un SP y estoy usando un dateadd(Day,@duracion,@fec_inicio);

Pero por ejemplo al sumarle 5 dias a la fec_inicio suma normalmente sin tomar en cuenta los días hábiles (Lunes a Viernes).

Nosé con que función hacer eso ........

Si me pueden Ayudar .....
  #2 (permalink)  
Antiguo 07/02/2006, 12:23
 
Fecha de Ingreso: noviembre-2002
Ubicación: Washington, DC
Mensajes: 822
Antigüedad: 21 años, 5 meses
Puntos: 5
La verdad no entiendo que es lo que intentas hacer...
Quieres que sume sabados y domingos? o solo de lunes a viernes?
__________________
Yanira
  #3 (permalink)  
Antiguo 07/02/2006, 16:57
Avatar de Mithrandir
Colaborador
 
Fecha de Ingreso: abril-2003
Mensajes: 12.106
Antigüedad: 21 años
Puntos: 25
Código:
/********************************************************************************************
**** returns date after given number of working days 
**** uses function fNextWorkingDay
**** 
**********************************************************************************************/
CREATE FUNCTION fAddWorkingDay (@Start datetime, @NumOfDays integer)
RETURNS datetime
AS
BEGIN
DECLARE @NextDay datetime
DECLARE @Counter int

IF @NumOfDays>0 
	 BEGIN
	        SET @Counter=1
	        -- Drop the time part and initialize the Return Variable
	        
	        SET @NextDay=CONVERT(datetime ,(CONVERT(char(10),@Start,102)),102 )
	        
	        WHILE @Counter <= @NumOfDays
		        BEGIN
			        SET @NextDay = dbo.fNextWorkingDay(@NextDay)
			        SET @Counter=@Counter+1
		        END
	 END
ELSE
	 BEGIN
	        SET @Counter=ABS(@NumOfDays)
	        -- Drop the time part and initialize the Return Variable
	        
	        SET @NextDay=CONVERT(datetime ,(CONVERT(char(10),@Start,102)),102 )
	        
	        WHILE @Counter>0
		        BEGIN
			        SET @NextDay = dbo.fPreviousWorkingDay(@NextDay)
			        SET @Counter=@Counter-1
		        END
	 END

RETURN @NextDay
END
http://www.sql-server-performance.co...TOPIC_ID=10395
__________________
"El hombre, en su orgullo, creó a Dios a su imagen y semejanza."
Friedrich Nietzsche
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 19:23.