Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
1 ACCEPTED SOLUTION
CLAYTONJS has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
5 REPLIES 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
CLAYTONJS has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That is perfect guys. Thank you very much. You have made my life much easier and my WFA workflows a lot cleaner.
Cheers,
Clayton
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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')
