简体   繁体   English

如何在mysql中从左到右获取日期?

[英]how to get the date from left to right in mysql?

what to do, that I get the Date like that 08-06-2017 and not 2017-06-08 ? 怎么办,我得到的日期是08-06-2017而不是2017-06-08 in the table of mysql 在mysql表中

Because I send the date_value to server like that 08-06-2017 因为我将date_value像这样发送到服务器08-06-2017 截图

Don't do it, it's going to be a mess. 不要这样做,这将是一团糟。 First of all the mysql date, date time and timestamp types do not support being stored in different formats. 首先,mysql的日期,日期时间和时间戳类型不支持以不同格式存储。 You could however select them with a different formatting, if you wanted to ( https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format ). 但是,如果您想( https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format ),可以使用其他格式选择它们。 If you absolutely have to store dates in a specific format, you would have to use text or varchar as type. 如果绝对必须以特定格式存储日期,则必须使用textvarchar作为类型。 But then your next problem is going to be ordering and grouping over date fields like that. 但是,接下来的问题将是像这样对日期字段进行排序和分组。

My recommendation would be to just stick with the mysql date format and do transformations between the different formats in whatever MVC framework you're using inside the controller or view. 我的建议是坚持使用mysql日期格式,并在您在控制器或视图内部使用的任何MVC框架中,在不同格式之间进行转换。 That's what they're for. 那就是他们的目的。 This also leaves you open for the possibility to use different date time formatting based on user locale. 这也使您可以根据用户区域设置使用不同的日期时间格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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