want to convert date to the above required format. Is it possible to write a groovy script to do so in datamapper? If yes can you please give an example. Or can i reference another expression or component?
Asked
Active
Viewed 5,980 times
5 Answers
4
I think the simplest way to do what you need is to edit the datamapper script and replace the line where you perform the date mapping for this one:
output.date = date2str(str2date(input.date,"d/mm/yy"), "yyyy-mm-dd");
but replacing the input and output fields accordingly.
0
Here is the link which explains how to do it in java. You may easily groovify it.
Here the script
import java.text.SimpleDateFormat
def OLD_FORMAT = "m/dd/yy"
def NEW_FORMAT = "yyyy-MM-dd"
// August 12, 2010
def oldDateString = "8/12/10"
def sdf = new SimpleDateFormat(OLD_FORMAT)
def d = sdf.parse(oldDateString)
sdf.applyPattern(NEW_FORMAT)
newDateString = sdf.format(d)
println "Date in modified format : $newDateString"
EDIT: Changed as per source format based on comment
0
#[server.dateTime.format('yyyy-MM-dd')]

chetan singhal
- 948
- 1
- 13
- 36
-
Please add some description/explanation to your code. – n00bProgrammer May 04 '15 at 13:44
0
I'm not a fan of such nesting.
I prefer a variation on the above answers, where I only keep the inner function:
output.date = str2date(input.date,"m/dd/yy")
but then defined the output format in the datamapper's graphical editor, by setting the field to a date with format "yyyy-MM-dd".
Both of these approaches work, but I find this method easier to read and far easier to explain to others.

Adam Katz
- 14,455
- 5
- 68
- 83

Andrew Mackenzie
- 1
- 1