How to add timestamp on MySQL outputfile?

Hi I'm making an event that runs every minute and extracts certain columns on a table and creates an output-file in excel format

Since I cannot overwrite the file, i wanted to append a time-stamp on the filename so it will create unique excel filenames.

Here is the sample of my event

CREATE EVENT IF NOT EXISTS 'Extract_Users'

ON SCHEDULE EVERY 1 Minute

COMMENT 'Data Extraction' DO SELECT userID, email, id FROM table_one.user_name

INTO OUTFILE 'C:\path\path\Desktop\test\user.xls'

Thank you!


Here is the answer to my question. This works.

DELIMITER $$

CREATE EVENT IF NOT EXISTS Extract_Users

ON SCHEDULE EVERY 1 Minute COMMENT 'Extract_Users'

DO

BEGIN

SET @sql_stmt := concat("SELECT userID, email, id FROM user_table.user_info INTO OUTFILE C:/path/path/desktop/test/Users-",DATE_FORMAT(now(),'%Y-%m-%d_%H%i%s'),".xls'");

PREPARE extrct FROM @sql_stmt;

EXECUTE extrct;

DEALLOCATE PREPARE extrct;

END $$

DELIMITER ;