fpdf将日期从YYYY-MM-DD更改为DD-MM-YYYY

时间:2014-03-31 10:53:19

标签: php sql date date-format fpdf

在我的phpmyadmin数据库中,年份保存为YYYY-MM-DD。但是当我生成pdf时,我想将其更改为DD-MM-YYYY。

enter image description here

代码:

$pdf->Table("SELECT measurements.title as Maling, routines.value as Verdi, routines.date as Dato, routines.time as Tid, pools.name as Basseng, emps.user_name as Ansatt
FROM routines, measure_routine, measurements, pools, emps
WHERE routines.id = measure_routine.routine_id
AND measure_routine.measure_id = measurements.id
AND (measurements.title  Like 'T_%') AND measure_routine.pool_id=pools.id AND routines.emp_id=emps.id AND Date between '".$fraDato."' and '".$tilDato."'
ORDER BY routines.date, routines.time;");


$prop=array('HeaderColor'=>array(255,150,100),
            'color1'=>array(210,245,255),
            'color2'=>array(255,255,210),
            'padding'=>2);




$pdf->Output($downloadfilename."$strf.pdf"); 
header('Location: '.$downloadfilename."$strf.pdf");
}

2 个答案:

答案 0 :(得分:3)

$pdf->Table("SELECT measurements.title as Maling, routines.value as Verdi, 
         date_format(routines.date as Dato, \"%d-%m-%Y\"), ...

答案 1 :(得分:1)

最好的方法是直接在sql中格式化日期,所以更改: routines.date as Dato来:

DATE_FORMAT(routines.date, '%d-%m-%Y') as Dato