0

I created an event in MYSQL with schedule date. For example the event fire on current month first date.

Am using the below query to select the current month first date

select CAST(DATE_FORMAT(NOW(),'%Y-%m-01') as DATE)

My doubt is how many time the event fire on that date.

Milton Fernando
  • 125
  • 1
  • 3
  • 10

1 Answers1

1

you can analyze your query using EXPLAIN

"EXPLAIN SELECT CAST(DATE_FORMAT(NOW(),'%Y-%m-01') as DATE)";

alternative:

if you want to find first day of current month then you can can create a custom function

DELIMITER ;;
CREATE FUNCTION FIRST_DAY(day DATE)
RETURNS DATE DETERMINISTIC
BEGIN
  RETURN ADDDATE(LAST_DAY(SUBDATE(day, INTERVAL 1 MONTH)), 1);
END;;
DELIMITER ;
That way:

Reference

and then call

SELECT FIRST_DAY(DATE(NOW()));
Community
  • 1
  • 1
xkeshav
  • 53,360
  • 44
  • 177
  • 245