Writing a SQL query is always interesting, and for me it’s never boring task. Recently I was developing a CRM for my company, In that I need to send mail to the users who have scheduled their task as a reminder so I taught of using cron job for the same.Well now I need to fetch the users to schedule the mail, here is the challenge; I have to set the cron job to run the file every 15 minutes, so I have to take out the users from current time to next 15 minutes.
We can achieve this by PHP, but I want to do it via mysql itself. After quick googling, I found a function called DATE_ADD().
Syntax:
My Query:
So adding 15 minutes to the current time becomes easier now by using the DATE_ADD() function. Likewise you can also add days to the date. Check here for more detailed information on DATE_ADD() function.
We can achieve this by PHP, but I want to do it via mysql itself. After quick googling, I found a function called DATE_ADD().
Syntax:
DATE_ADD(date_time,INTERVAL expr type)
My Query:
SELECT * FROM table_task WHERE field_remainder BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 15 MINUTE)
So adding 15 minutes to the current time becomes easier now by using the DATE_ADD() function. Likewise you can also add days to the date. Check here for more detailed information on DATE_ADD() function.
0 comments:
Post a Comment