Change the date format in phpmyadmin

前端 未结 3 1051
花落未央
花落未央 2021-02-04 16:48

I m trying to change the date format in phpmyadmin. I m unable to change the format I want to change the format to dd-mmm-yyyy. How can I change the date format. Please help me

相关标签:
3条回答
  • However, it's easy to change in PHP.

    $myinput='2005/15/09'; $sqldate=date('d-m-Y',strtotime($myinput)); echo $sqldate; 
    

    Now 09-15-2005.

    0 讨论(0)
  • 2021-02-04 17:32

    You can use phpMyAdmin's browser transformations feature to do this.

    • Go to the Structure page of the relevant table.
    • Click on the Change hyperlink in the Actions column of the relavent date/datetime/timestamp column.
    • Chose Text/Plain: Dateformat from the Browser Transformation dropdown.
    • Insert 0,'%d-%b-%Y','local' into the transformation options column.
    • Save the changes and go back to Browse page.

    From the documentation on Text/Plain: Dateformat transformation

    Displays a TIME, TIMESTAMP, DATETIME or numeric unix timestamp column as formatted date. The first option is the offset (in hours) which will be added to the timestamp (default: 0). Use second option to specify a different date/time format string. Third option determines whether you want to see local date or UTC one (use "local" or "utc" strings) for that. According to that, date format has different value - for "local" see the documentation for PHP's strftime() function and for "utc" it is done using gmdate() function.

    0 讨论(0)
  • 2021-02-04 17:38

    It's not possible as far as I know. I stand corrected, see @Madhura Jayaratne's answer for how to change the date format using phpMyAdmin. However, if that's not available or you don't have permission, you can use the solution below to reformat it in PHP.

    Let's say your $date_from_sql is set to 2014-03-23.

    $date = date('d-m-Y', strtotime($date_from_sql)); //date format
    

    Now $date equals 23-03-2014


    Optionally you can wrap it in a function to use it throughout your application.

    function fixdate($date) {
        return date('d-m-Y', strtotime($date));
    }
    
    // When parsing data from the database:
    $query = query("SELECT wrongdate FROM something")->result();
    $date = fixdate($query->date);
    
    0 讨论(0)
提交回复
热议问题