Date time conversion in APIM
search cancel

Date time conversion in APIM


Article ID: 105208


Updated On:


CA API Gateway


This article illustration how to convert the date time to different format.

For example, convert a date with format "13/Jul/2018 10:30" to another format "2018-07-13T10:30:00" 


All supported versions of the API Gateway


The following steps are based on the following example:
1. add custom datetime format 
Add following line to the end of cluster-wide property datetime.customFormats: 
dd/MMM/yyyy HH:mm 

(NOTE: only the last line doesn't require semicolon";", so you should add ; to the end of the line before last line) 

2. set context variable 
Date type: Date/Time 
Date Format: dd/MMM/yyyy HH:mm (select the new format from the dropdown list) 
Expression: 13/Jul/2018 10:30 (you can use a string variable instead) 

3. formatting output 
${<your datetime variable>.yyyy-MM-dd'T'HH:mm:ss} 

sample policies, (copy the xml and paste to you policy window) 
<?xml version="1.0" encoding="UTF-8"?> 
<wsp:Policy xmlns:L7p="" xmlns:wsp=""> 
<wsp:All wsp:Usage="Required"> 
<L7p:Base64Expression stringValue="MTMvSnVsLzIwMTggMTA6MzA="/> 
<L7p:VariableToSet stringValue="orgdatestring"/> 
<L7p:Base64Expression stringValue="JHtvcmdkYXRlc3RyaW5nfQ=="/> 
<L7p:DataType variableDataType="dateTime"/> 
<L7p:DateFormat stringValue="dd/MMM/yyyy HH:mm"/> 
<L7p:DateOffsetExpression stringValue=""/> 
<L7p:VariableToSet stringValue="newdate"/> 
<L7p:Base64ResponseBody stringValue="b2xkIGRhdGU6ICR7b3JnZGF0ZXN0cmluZ30KbmV3IGRhdGU6ICR7bmV3ZGF0ZS55eXl5LU1NLWRkJ1QnSEg6bW06c3N9"/> 
<L7p:ResponseContentType stringValue="text/plain; charset=UTF-8"/> 

Additional Information

As per the 2nd document, for the details of datetime patterns, please refer to,