将日期和时间添加到输出文本文件中



我想为输出文本文件添加日期和时间。

例如OrderData1506241249,我该怎么做?我使用wamp和mysql工作台来完成这项工作。请帮忙。

$sql4 = "
    SELECT * FROM FOrder
    INTO OUTFILE 'OrderData.txt'
    FIELDS TERMINATED BY ',' 
    LINES TERMINATED BY 'rn';

要将其添加为列,只需更改查询以包含now()函数:

SELECT *, now() as [Current Date] FROM FOrder

如果你想让它只在数据上方或下方显示一次,你总是可以对所有数据进行并集。假设MyTable有两个字段,id int和name varchar

$sql4 = "
    SELECT * FROM FOrder
    UNION ALL SELECT 0, 'Report Date: '+cast(now() as char) as [name]
    INTO OUTFILE 'OrderData.txt'
    FIELDS TERMINATED BY ',' 
    LINES TERMINATED BY 'rn';

我认为您的意思是希望将日期和时间添加到导出要放入的文件名中。

所以试试这个

$datetime = date('ymdHi');
$sql4 = "
    SELECT * FROM FOrder
    INTO OUTFILE 'OrderData$datetime.txt'
    FIELDS TERMINATED BY ',' 
    LINES TERMINATED BY 'rn'";

相关内容

  • 没有找到相关文章

最新更新