Active IQ Unified Manager Discussions
Active IQ Unified Manager Discussions
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
Solved! See The Solution
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
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!
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
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
That is perfect guys. Thank you very much. You have made my life much easier and my WFA workflows a lot cleaner.
Cheers,
Clayton
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')