Active IQ Unified Manager Discussions

WFA - MVEL Function to get current date

CLAYTONJS
13,562 Views

Has anybody been able to create an MVEL function to get the current date? Or is this even possible?

 

I was hoping to use this so that when I called the function it would return a date in a format i.e. ddMMMyyyy. I've been reading up and have been trying different things, but have had no luck what so ever.

 

Any help is appreciated.

 

Cheers,

Clayton

1 ACCEPTED SOLUTION

sinhaa
13,541 Views

Good solution terentino. As an alternative which completely gives date in format ddMMyyyy is the below function.

 

====

def GetDate(hello) {
import java.util.*;
import java.text.SimpleDateFormat;

return new SimpleDateFormat("ddMMyyyy").format(Calendar.getInstance().getTime());
}

 

====

 

Call it the same way like GetDate(1).

 

 

sinhaa

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

View solution in original post

5 REPLIES 5

trentino123
13,558 Views

Hi Clayton,

 

Try a new function with this MVEL code :

 

def Timestamp(hello) {

import java.util.Date;

d=new Date();

 return d;

}

 

During the test call it with Timestamp(1) , so it is not empty in the inputs, the number 1 is not used.

 

Hope it helps.

 

Thanks!

sinhaa
13,542 Views

Good solution terentino. As an alternative which completely gives date in format ddMMyyyy is the below function.

 

====

def GetDate(hello) {
import java.util.*;
import java.text.SimpleDateFormat;

return new SimpleDateFormat("ddMMyyyy").format(Calendar.getInstance().getTime());
}

 

====

 

Call it the same way like GetDate(1).

 

 

sinhaa

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Adai
13,537 Views

Hi Clayton,

          I got this from one of the community contributors, bestinj.

 

def getDate(data)
{
java.util.Calendar cal= java.util.Calendar.getInstance(java.util.Locale.getDefault()) ;
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("HH-mm-MM-dd-yy");
return format.format(cal.getTime());
}

 

Call the function as getDate(1)

 

 

Thanks to bestinj for the help

 

You can play with the SimpleDateFormat("HH-mm-MM-dd-yy") for different date formats.

 

Hope this helps.

 

Regards

adai

 

 

CLAYTONJS
13,530 Views

That is perfect guys. Thank you very much. You have made my life much easier and my WFA workflows a lot cleaner.

 

Cheers,

Clayton

Siegfried
12,883 Views

Above solutiuons caused a syntax error on my system, so I created this one : 

 

def getDate(dateFormat) {

// dateFormat - string for SimpleDateFormat

import java.text.SimpleDateFormat;
import java.util.Date;
Date curDate = new Date();
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
String DateToStr = format.format(curDate);
return (DateToStr);
}

 

 You call it : getDate('yyyy_MM_dd')

Public