English 中文(简体)
How to compare two dates with only month and year in mule
原标题:

My scenario is to check if the Month and year (in date value) is less than the current month and year (in current date value).

The condition I need to implement is this

if source-month&year  < current-month&year Yes else No 

Scenario 1:current date = 03/29/2024 (MM/dd/yyyy) and source incoming date = 03/01/2021 (MM/dd/yyyy). In this case it should give me Yes

Scenario 2: current date = 03/29/2024 (MM/dd/yyyy) and source incoming date = 03/01/2024 (MM/dd/yyyy). In this case it should give me No.

I tried using .month and .year but it always giving result as No

问题回答

Try this and let me know if it is working as you expected .upvote if it is working

%dw 2.0
output application/json

var currentDate = now()
var currentYear = currentDate.year
var currentMonth = currentDate.month
var inputDate = "03/01/2024" as String {format: "MM/dd/yyyy"}
var inputYear = (inputDate as Date {format: "MM/dd/yyyy"}).year
var inputMonth = (inputDate as Date {format: "MM/dd/yyyy"}).month

---
if (inputYear < currentYear or (inputYear == currentYear and inputMonth < currentMonth)) 
    "Yes"
else 
    "No"

I d probably turn both of the dates into the first of the month and then compare.

%dw 2.0
output application/json

var a = |2024-03-23T02:47:40.014782Z|
var b = |2024-03-30T02:48:34.216274Z|

fun firstOfMonth(d) = 
    d as String {format: "yyyy-MM-01"} as Date
---
{
    a: a,
    b: b,
    less: firstOfMonth(a) < firstOfMonth(b)
}




相关问题
Mule ESB - How to get MimeMessage instead of MimeBodyPart?

I m trying to get the FROM email address in Mule ESB. I m getting the retrieved object as MimeBodyPart, I d like to have MimeMessage instead. How to do this? Any solution - either in Mule or Java is ...

JaxWsProxyFactoryBean for Mule CXF transport?

I am new to mule. Are there any way to call CXF based web services using JaxWsProxyFactoryBean? It will be nice to reuse Java interface instead of wsdl files. With CXF we can simply reuse our java ...

Drools, spring and mule

Has anyone combined these technologies? Could you share lessons learnt?

How to keep inbound host with custom Mule ESB router

I created a custom router with one endpoint. The custom router looks up the destination of the endpoint based on the URL parameters of the inbound URL. I have an example of this up and running, and I ...

热门标签