Good evening, this code helped me to obtain the first day of the week and the last day of the week from the current date (there is not all the code of the stored procedure)
CREATE DEFINER= root
@ localhost
PROCEDURE bsp_listar_turnos_semanal
() BEGIN
SELECT
t.Id_Turno,
m.Nombre,
m.Apellido,
p.Nombre,
p.Apellido,
t.Fecha_Programada,
t.N_Orden
FROM turnos t
INNER JOIN medicos m on t.Id_Medico = m.Id_Medico
INNER JOIN pacientes p on t.Id_Pacientes = p.Id_Pacientes
WHERE t.Fecha_Programada between SUBDATE(now(),WEEKDAY(now())) and
ADDDATE(now(),6-WEEKDAY(now())) ;
END
my question is how to get the first and last day of a week, entering any date. Thank you very much, I hope you understand
Depending on whether the week starts on Sunday or Monday, you have to do the calculation one way or another:
Departure:
fiddler
See test code here:
Demostración
Inside the PROCEDURE
To put it inside the procedure, the code would be more or less like this:
And to call it you pass a valid date format
YYYY-MM-DD
enclosed in quotes: