简体   繁体   English

Wordpress最灵活的日期格式

[英]Wordpress most flexible format for dates

I am using a library called Custom Metaboxes and Fields for Wordpress to add meta data to my custom post types. 我正在使用一个名为Wordpress的自定义元框和字段的库将元数据添加到我的自定义帖子类型中。 It's an event website. 这是一个活动网站。

I had it all going, but started to have issues with sorting when trying to filter the adjacent_post_links from singe posts. 我拥有了一切准备,但开始有试图筛选时的排序问题, adjacent_post_links从烧毛职位。

I figured it might be that I am storing the date in m/d/y and not Y/m/d. 我认为这可能是因为我将日期存储在m / d / y中而不是Y / m / d中。

So, i've started over trying to work with a UNIX date timestamp as I have read this is the way to go. 因此,我已经开始尝试使用UNIX日期时间戳,因为我已阅读了这条路。 Now, I am having issues with my custom wp_queries pulling my filtered posts on the front page. 现在,我的自定义wp_queries在首页上过滤已过滤的帖子时遇到了问题。 I think it has to do with needing to work with timezones. 我认为这与需要使用时区有关。

Anyways, over the long run, what are the best practices in storing date in mysql? 无论如何,从长远来看,在mysql中存储日期的最佳实践是什么? I've also been reading about using STR_TO_Date() to properly format date so that you can order and compare dates if needed. 我还读过有关使用STR_TO_Date()正确格式化日期的信息,以便您可以根据需要订购和比较日期。 Would this be an option if I went back to dates being stored in m/d/y . 如果我回到存储在m / d / y中的日期,是否可以选择?

Thanks 谢谢

If you store dates as Unix timestamps in the database, it 'll gives you lots of trouble because it is not easily readable.for Example(unix format): '1410738238' 如果将日期作为Unix时间戳存储在数据库中,则会给您带来很多麻烦,因为它不容易阅读。例如(unix格式):'1410738238'

if you store as datetime format in the database, it is easy readable efficient and very flexiable,also mysql provides a lot of date functions.for Example(datetime format): '1970-01-01 00:00:01' 如果您将datetime格式存储在数据库中,则它易于阅读,高效且非常灵活,mysql还提供了许多日期函数。例如(datetime格式):'1970-01-01 00:00:01'

for more information http://dev.mysql.com/doc/refman/5.1/en/datetime.html 有关更多信息,请访问http://dev.mysql.com/doc/refman/5.1/en/datetime.html

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

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