It's all about the answers!

Ask a question

Subtraction of date from creation date

Tijo Joy (111) | asked Nov 25 '13, 5:42 a.m.
 Hi All, 

I using RTC and trying to create a new date attribute which is to display creation date - 1. 

I have tried to use"")), "day", -1)  and it is not working. 

I'm not sure what is wrong with this. I would appreciate any help on this. 
Thanks in Advance


N Z commented Nov 25 '13, 4:44 p.m.

 You have to return a Date object, not sure on the exact syntax, but something like:

var newDate = Date(myDate), {milliseconds:true, zulu:true});

where myDate is the output of your command above.

One answer

permanent link
Ralph Schoon (62.9k33645) | answered Nov 25 '13, 5:52 a.m.
I am not sure if this helps, but this a calculation with dates:
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2011. All Rights Reserved.
 * Note to U.S. Government Users Restricted Rights:  
 * Use, duplication or disclosure restricted by GSA ADP Schedule 
 * Contract with IBM Corp. 

dojo.require(""); // To access the work item attributes
dojo.require(""); // To create a status object to return
dojo.require(""); // To create a severity for the status
dojo.require(""); // We need the date class from Dojo to compare two dates
dojo.require(""); // We need the stamp class to work with ISO date strings

(function() {
var Severity =;
var Status =;

var DateValidator = dojo.declare("org.example.DateValidator_30_days_later", null, {

    validate: function(attributeId, workItem, configuration) {
        var severity= "ERROR"; 
        var message= "Date must be at least 30 days from now"; 
       // Work Item new: not initialized - provides todays date. Once created provides the creation date 
        var beginDate ="")); 
        // Get the current attribute's value and make a Date object from it
        console.log("I got: ["+workItem.getValue(attributeId)+"]");
        var endDate=;        
        // Compare the two dates returns negative value due to order
        var compare = -(, beginDate, "day"));
        if (compare>= 30) { // make sure endDate is not earlier than beginDate + 30
            return Status.OK_STATUS;
        } else {
            return new Status(Severity[severity], message + " current value: [" +endDate + "] and difference is " + compare);

Your answer

Register or to post your answer.