Php 使用join时如何将日期字段从数据库反转为xls文件

Php 使用join时如何将日期字段从数据库反转为xls文件,php,mysql,date,xls,Php,Mysql,Date,Xls,我正在使用php mysql,我正在从数据库值生成一个XLS文件,但我的问题是,日期字段的格式是2014-01-05,但我希望它在我的XLS文件中是05-01-2014。我通过联接查询显示所有字段(因此使用select*),这就是为什么我无法分离日期字段以将其转换为所需格式的原因。我怎样才能做到这一点 以下是生成XLS的SQL查询: select * from registration join programme on registration.id=programme.stuid jo

我正在使用php mysql,我正在从数据库值生成一个XLS文件,但我的问题是,日期字段的格式是
2014-01-05
,但我希望它在我的XLS文件中是
05-01-2014
。我通过联接查询显示所有字段(因此使用
select*
),这就是为什么我无法分离日期字段以将其转换为所需格式的原因。我怎样才能做到这一点

以下是生成XLS的SQL查询:

select * from  registration 
join programme on registration.id=programme.stuid 
join family on registration.id = family.stuid 
join address on registration.id = address.stuid 
join education on registration.id = education.stuid 
join extradetail on registration.id=extradetail.stuid 
join workexperience on registration.id=workexperience.stuid 
join demanddraft on registration.id = demanddraft.stuid 
where (DATE(demanddraft.ApporvedDate) >= '".$term1."' 
    AND DATE(demanddraft.ApporvedDate) <= '".$term2."') 
    AND demanddraft.ddstatus = 'Approved'
从注册中选择*
注册时加入计划。id=program.stuid
注册时加入family.id=family.stuid
注册时的加入地址.id=address.stuid
注册时加入教育。id=education.stuid
注册时加入extradetail.id=extradetail.stuid
注册时加入workexperience.id=workexperience.stuid
注册时加入demanddraft.id=demanddraft.stuid
其中(日期(demanddraft.ApprovedDate)>=“$term1.”

和DATE(demanddraft.approveddate)您只需要重新格式化包含所讨论日期的字段,我假设在我的示例中它被称为
DateFieldName

您正在处理查询结果集的位置执行以下操作

//start while loop to get data
while($row = mysql_fetch_row($result))
{
    list($y,$m,$d) = explode( '-', $row['DateFieldName'] );
    $row['DateFieldName'] = sprintf( '%s-%s-%s', $d, $m, $y );

使用strotime()函数。显示正在创建
XLS
文件的代码。编辑您的问题不要将其放在评论中!@riggsfully:我已经编辑了我的问题,请检查。
//start while loop to get data
while($row = mysql_fetch_row($result))
{
    list($y,$m,$d) = explode( '-', $row['DateFieldName'] );
    $row['DateFieldName'] = sprintf( '%s-%s-%s', $d, $m, $y );