简体   繁体   中英

Add mysql OR php trigger to change datetime format from US to UK for any query that return datetime

I have A system build on YII using US date format, by my client ask me to change the format to UK format, the problem is the system is too big and I can not take around the whole system code to change the presenting format.

is there a way to add a trigger for date,datetime fields to return in UK format in php or mysql.

thanks

You asked:

is there a way to add a trigger for date,datetime fields to return in UK format in php or mysql.

No.

The MySQL internal datetime format is not changeable. The only locale-sensitive setting in the DBMS is the language in which the names of months and weekdays are rendered. In the US, we got those names from England. So that doesn't help.

If you want MySQL to render dates from its tables in Euro format (25.12.2015) you need this.

     DATE_FORMAT(datevalue, '%e.%c.%Y')

If you have the dates in php, you can use this sort of thing.

    date('j.n.Y', $datevalue);

Many php applications offer a global $DATEFORMAT string constant, that can be changed for use in a different locale. You may want to adapt your code to do this. For example, the WordPress team have sorted this out very nicely indeed. https://codex.wordpress.org/Formatting_Date_and_Time

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM