Mysql Adding date/time stamp to file produced, or other method of automated file naming to keep resulting files unique SELECT 
'&quot;Part #&quot;',
'&quot;Manu&quot;',
'&quot;Qty&quot;',
'&quot;partdesc&quot;',
'&quot;Rohs status&quot;'
UNION all 
(
SELECT partno, manuf, qtyleft, partdesc, stfifo.ROHScompliance
    FROM stmaster, stfifo
    WHERE stmaster.internal = stfifo.internal AND stfifo.warehouse = 'MAIN'

AND manuf != 'aaaa' 
AND manuf &lt;&gt;'bbbb' 
AND manuf &lt;&gt;'cccc' 

AND stmaster.partno &lt;&gt;'yyyyyyyyy' 
AND stmaster.partno &lt;&gt;'xxxxxxxx' 
AND QTY &gt;0
GROUP BY partno, manuf
ORDER BY partno ASC
INTO OUTFILE
    'D:/Reporting/abc - 19.03.15.xls' 
    FIELDS TERMINATED BY '  ' ENCLOSED BY '' LINES TERMINATED BY ''

How do I make it so that the resulting file includes today's date as determined by a NOW() function? CONCAT() functions seem useless as the file is within a UNION all() function. At the moment I cannot run this query more than once without deleting the .xls file first. Any other workarounds are greatly welcomed. Thanks in advance
You may need to use shell script for this.
First write a script to do so.. a sample is as below
!/bin/bash

dto=date +%d'_'%b'_'%Y'_'%H_%M_%S
mysql -uroot -p dbname -e &quot; select * from table_name into outfile 'file1_$dto' &quot;

This will always give you unique names against your files.
Hope it helps.