Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
Necesito obtener la fecha y hora de apertura del día siguiente para la biblioteca

necesito obtener la hora y la fecha del día siguiente para la biblioteca según la siguiente tabla en MySQL sin usar procedimientos

 CREATE TABLE `library_timing` ( `id` int(11) NOT NULL AUTO_INCREMENT, `store_id` int(10), `day` varchar(10) DEFAULT NULL, `start_time` time DEFAULT NULL, `end_time` time DEFAULT NULL, PRIMARY KEY (`id`) ); Insert into library_timing values(1,1,"Monday",'09:00:00','18:00:00'); Insert into library_timing values(2,1,"Tuesday",'09:00:00','18:00:00'); Insert into library_timing values(3,1,"Thrusday",'09:00:00','18:00:00'); Insert into library_timing values(4,1,"Friday",'09:00:00','18:00:00');

Como puede ver, tengo un día de tiempos para la biblioteca, por lo que el resultado esperado es el siguiente

(Considerar que hoy es LUNES 25 de junio de 2020)

 ID. Next opening Time 1 26-06-2020 09:00:00

Y (Considerar si hoy es MARTES 26 DE JUNIO DE 2020 y MIÉRCOLES ES FERIADO así que FECHA HORA PARA EL JUEVES)

 ID. Next opening Time 1 28-06-2020 09:00:00

He probado este caso hasta ahora, lo que me da tiempo para los próximos días, pero no estoy seguro de cómo hacerlo si hay una brecha de más de 1 día.

 case when (curtime() < start_time or curtime() > end_time) or (start_time = "00:00:00" and end_time = "00:00:00") or (start_time is null and end_time is null) then UNIX_TIMESTAMP(( select TIMESTAMP(curdate()+1,( select start_time from library_timing a where a.store_id = s.id and day = DAYNAME(CURDATE() + 1) )) )) else 0 end nextopeningtime
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Puedo aconsejar la siguiente solución:

  • agregue la columna day_of_week para el número de días de la semana para simplificar el cálculo:
 CREATE TABLE `library_timing` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `store_id` INT(10), `day_of_week` INT(10), `day` VARCHAR(10) DEFAULT NULL, `start_time` TIME DEFAULT NULL, `end_time` TIME DEFAULT NULL, PRIMARY KEY (`id`) ); INSERT INTO library_timing VALUES(1,1,2,"Monday",'09:00:00','18:00:00'); INSERT INTO library_timing VALUES(2,1,3,"Tuesday",'09:00:00','18:00:00'); INSERT INTO library_timing VALUES(3,1,4,"Thrusday",'09:00:00','18:00:00'); INSERT INTO library_timing VALUES(4,1,5,"Friday",'09:00:00','18:00:00');
  • a continuación podemos usar el siguiente enfoque:

     SELECT * FROM ( -- check currently open SELECT 'Open' , `lt`.* FROM `library_timing` `lt` WHERE `lt`.`day_of_week` = DAYOFWEEK('2020-06-29') AND -- '2020-06-29' will be changed to CURRDATE() CURTIME() BETWEEN `start_time` AND `end_time` UNION -- check open next day SELECT * FROM ( SELECT 'Next' , `lt`.* FROM `library_timing` `lt` WHERE `lt`.`day_of_week` > DAYOFWEEK('2020-06-29') -- '2020-06-29' will be changed to CURRDATE() LIMIT 1 ) nextday UNION -- check first working day SELECT 'Next' , `lt`.* FROM `library_timing` `lt` WHERE `lt`.`day_of_week` = 2 ) opentime LIMIT 1;

Este enfoque no es ideal y se puede mejorar.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda