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

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -