SQL genius help for custom query

I know there are some legends with SQL out there.
What I need to do is create a custom query using the following path

Select from m_info
table m_dob

I then need to split the m_dob to day, month and compare it to the current day, month of the server.

Does anyone have any ideas??

Should help you on your way.

1 Like

Yep worked it out @Dave cheers for the response.

Heres the code just in case anyone else needs to do this.

Today Birthday:
SELECT m_dob, m_name
FROM m_info
WHERE EXTRACT(MONTH FROM m_dob) = MONTH(CURDATE()) AND EXTRACT(DAY FROM m_dob) = DAY(CURDATE())

This Month:
SELECT m_dob, m_name
FROM m_info
WHERE EXTRACT(MONTH FROM m_dob) = MONTH(CURDATE()) AND EXTRACT(DAY FROM m_dob) > DAY(CURDATE())

3 Likes

Hello, I am try to use but not it doesn’t working.

SELECT nome, data_nasc
FROM pacientes
WHERE EXTRACT(MONTH FROM data_nasc) = MONTH(CURDATE()) AND EXTRACT(DAY FROM data_nasc) = DAY(CURDATE())

table : pacientes
nome : name
data_nasc : date of birth

Looks like you need to pick an Expression for the input as P1 has no value to query… Or remove the Parameter and run he query again, make sure to hit the little ‘Play’ button icon to fetch the schema.

Works, but I needed to do some modifications :

SELECT nome, data_nasc
FROM pacientes
WHERE EXTRACT(MONTH FROM data_nasc) = ({{NOW.formatDate(‘MM’)}}) AND EXTRACT(DAY FROM data_nasc) = ({{NOW.formatDate(‘dd’)}})

1 Like

How can I select value with some data from $_SESSION ?

For example :

SELECT nome, data_nasc, pk_clinica
FROM pacientes
WHERE EXTRACT(MONTH FROM data_nasc) = ({{NOW.formatDate(‘MM’)}}) AND EXTRACT(DAY FROM data_nasc) = ({{NOW.formatDate(‘dd’)}}) AND (pk_clinic = {{$_SESSION.clinic}})