You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mendix新手:如何用XPath筛选上月日期数据及获取上月起止日期

Mendix上月数据筛选:日期范围获取与XPath查询

一、快速获取上月的月初和月末日期

Mendix自带的日期函数可以直接生成所需日期,不用手动计算每个月的天数:

  • 上月月初:使用startOfMonth(addMonths(currentDateTime(), -1))
    先通过addMonths(currentDateTime(), -1)定位到上月的任意日期,再用startOfMonth直接返回该月的第一天(日期类型默认是当月第一天00:00,时间类型同理)
  • 上月月末:使用lastDayOfMonth(addMonths(currentDateTime(), -1))
    同样先定位到上月,再用lastDayOfMonth返回该月最后一天。如果你的属性是DateTime类型,要覆盖当天全时段数据,可以把月末时间调整为23:59:59,用addSeconds(lastDayOfMonth(addMonths(currentDateTime(), -1)), 86399)

你可以把这两个计算结果存成变量(比如$StartOfLastMonth和$EndOfLastMonth),方便后续重复使用。

二、用XPath检索上月范围内的数据

假设你的目标实体是YourEntity,日期属性为DateAttribute,用以下XPath表达式即可筛选符合条件的数据:

//YourEntity[DateAttribute >= $StartOfLastMonth and DateAttribute <= $EndOfLastMonth]

如果不想提前定义变量,也可以直接在XPath中嵌入日期计算函数:

//YourEntity[DateAttribute >= startOfMonth(addMonths(currentDateTime(), -1)) and DateAttribute <= lastDayOfMonth(addMonths(currentDateTime(), -1))]

如果是DateTime属性且需要覆盖全天,调整后的XPath:

//YourEntity[DateAttribute >= startOfMonth(addMonths(currentDateTime(), -1)) and DateAttribute <= addSeconds(lastDayOfMonth(addMonths(currentDateTime(), -1)), 86399)]

内容的提问来源于stack exchange,提问作者Predrag Mirkovic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 23:44:58