php - How to set $variable as a DATE_FORMAT in MySQL -
i have created 1 variable changing date format in mysql query not working me there way use variable date-format in mysql query ?
my code here
<?php $con = mysql_connect(); mysql_select_db(); $dateformat = '%d-%m-%y'; $result = mysql_query("select *, date_format(2014-11-18, $dtformat) nicedate tablename;"); $data = array(); while ( $row = mysql_fetch_row($result, true) ) { $data[] = $row; } echo json_encode($data); ?>
you need pass $dateformat
instead of $dtformat
string in mysql.
<?php $con = mysql_connect(); mysql_select_db(); $dateformat = '%d-%m-%y'; $result = mysql_query("select *, date_format('2014-11-18', '".$dateformat."') nicedate tablename;"); $data = array(); while ( $row = mysql_fetch_row($result, true) ) { $data[] = $row; } echo json_encode($data); ?>
Comments
Post a Comment