在 makumba 中使用日期函数进行操作
尝试日期函数。想要列出仅 10 天前的帖子,早于该时间的帖子,我不会显示。我有这样的查询:
dayOfYear($now)-dayOfYear(p.TS_create)<10 和year($now)=year(p.TS_create)
位于:
它有效,但只是想问是否有更好的方法来做到这一点。
trying out date functions. Want to list posts only 10 days old, older than that, I won't show. I have this query:
dayOfYear($now)-dayOfYear(p.TS_create)<10 and year($now)=year(p.TS_create)
inside of:
<mak:list from="general.forum.Post p" where="dayOfYear($now)-dayOfYear(p.TS_create)<10 and year($now)=year(p.TS_create)">
It works, but just want to ask if there is any better way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,这可能不是最好的选择。
首先,
year($now)=year(p.TS_create)
将导致在 1 月 1 日您将看不到前几年最后 9 天的帖子(我猜您也想看看)。否则,
dayOfYear()
可能会起作用,但由于它代表一年中的一天(而不是自最小日期以来的总天数),更好的选择是使用类似以下内容:PS Also请记住,如果您使用
$now
,则必须将其设置为上下文属性,但是在 MQL 中,您可以使用一个函数now()
来代替。因此,如果您不在页面的其他位置(例如在c:if
语句中)使用$now
,最好使用该函数。Well this is probably not the best option.
First of all
year($now)=year(p.TS_create)
will result that on the 1st of Jan you would not see the posts from the last 9 days of the previous years (which I guess you would want to see also).Otherwise, the
dayOfYear()
would probably work, but since it represents a day in a year (and not total number of days since min date possible) the better option would be to use something like:P.S. Also have in mind that if you use
$now
you have to set it as context attribute, however inside MQL you have a functionnow()
which you can use instead. So if you're not using$now
in other places in the page (like inc:if
statements) it's better to use the function.另一种选择是使用以毫秒为单位的日期的数字表示形式,如下所示:
(10 * 24 * 60 * 60 * 1000 等于 10 天)
请注意,这两种解决方案(使用毫秒或 dateAdd(p.TS_create, 10, ' day') > now()) 实际上会比较 240 小时,并忽略日历天数。
Another option is to use the numerical representation of dates in milliseconds, as in the following:
(10 * 24 * 60 * 60 * 1000 equals to 10 days)
mind that both solutions (using millisecond or dateAdd(p.TS_create, 10, 'day') > now()) will actually compare 240 hours, and disregard calendar days.