Hi there!
I am searching for a date object that contains the current system date. Once I have this, I want to subtract 30 days and get therefore get another date. Does anybody know how I can access the system date in the ARIS scripting language? And are there possiblities to format the date (e.g. DD.MM.YY) to compare it with other dates from user defined attributes?
Thanks in advance!
Markus
Hello Markus,
you can use the standard Date() object in javascript to achieve that:
var today = new Date() // this will give you the current system date in a Date object today.setDate(today.getDate() - 30) // this will take 30 days off today's date
If you prefer a more precise time you can use today.getTime(), that will return the number of millisecond since 01/01/1970. I hope it helps.
Hello Charles!
Thanks a lot for this very useful hint, that will keep me going!
However, this problem solved keeps another one popping up. Now I have the system date but I can't compare it with my user defined date attribute. What I want to do is to compare both month if they differ. I get the system date's month with the method date.getMonth().
The system date delivers:
Tue Jun 28 2011 06:24:37 GMT+0200 (MESZ)
I have defined a user attribute (fdate) of the type date which delivers in the report:
28.06.2011
Unfortunately I can't use the method fdate.getMonth() to compare the current month with the month of the user defined date attribute.
Do you have any suggestions for this case? What is the type within ARIS of user defined date attributes? Thanks very much in advance!
Markus
Hello Markus,
if you are using Object.Attribute().getValue(), ARIS will return you a String. You cann usethat string to create a Date if you want to:
var fdateString = aObject.Attribute(XXXX, nLocal).getValue() // this will get the value of the custom attribute you created var fdateDate = new Date(fdateString) // this will create a Date object from the string value of the attribute
once you have your dates you can compare using standard comparisons:
var today = new Date() var fdateDate = new Date(fdateString) if (fdateDate > today) { // fdate is in the future }
I hope it helps
Nice to read this, but actually i am searching to convert a date from "Nov 5, 2010 6:49:15 AM" into "05-11-2010" (dd-mm-yyyy)
How can i do this, both examples does not work:
strtypeo = __toString(ocurrentattribute.Type());
strvalue = __toString(__toString(ocurrentattribute.GetValue(true)));
if (strtypeo == "Time of generation") {
formatter = new SimpleDateFormat("dd-mm-yyyy");
strgenerationm = formatter.format(strvalue);
}
or
strtypeo = __toString(ocurrentattribute.Type());
strvalue = __toString(__toString(ocurrentattribute.GetValue(true)));
if (strtypeo == "Time of generation") {
strgenerationm = dateFormat(strvalue,"dd-mm-yyyy");
}
Hi Jan!
Yes, I was also looking for exactly that conversion but I haven't found a possibility to use the java.util.* and the java.text.* packages of java in javascript. And the text-package contains the new SimpleDateFormat object. I also tried this, but I was not able to import them.
What you also could do is to get the day, month and year like this and build up a date string with this.
var date = new Date();
var day = date.getDay();
var month = date.getMonth();
var year = date.getYear();
string convDate = day + "-" + month + "-" + year;
so the string convDate should contain for example 05-07-2011
greetings,
Markus
Hi all,
You can use "new java.util.Date()" or simply "new Date()" to create the date object and can see the methods that can be used
http://download.oracle.com/javase/1.5.0/docs/api/java/util/Date.html
Just some things to remember
1. If you use it in Reports, then the date returned is server date. Using it in Macro returns your local system date.
2. The month returned by Date.getMonth() method is 1 month less, as the index starts from 0. Same while creating date object, the number provided for month should be -1 the actual month number. Try these with some small test script.
Comparing Date :-
For comparing dates, string compare is not a good option, and it may include a lot of comparing logic also. The best way to comapare the date, or to subtract some no of days, or to find out the difference of dates, is to convert both the dates to milliseconds and do the comparision. Date.getTime() method can give the milliseconds.
@Markus, comparing the date might be wrong if both the dates are in different GMT string. 30 days milliseconds can be found out by 30*24*60*60*1000
So your steps should be
1. Read the date stored in attribute as string.
2. Create a Date object from that string. Find out the milliseconds.
3. Get the system date. Find out the milliseconds.
4. Find out difference in Milliseconds.
5. Find out days, Days = (((((Difference in Milliseconds)/1000)/60)/60)/24). You can use Math.round(), Math.floor() or Math.ceil() methods to round the number if required.
Now you can compare the Days with 30 or any other value.
Thanks,
Amol Patil
Thanks,
I have found the solution (use MM to see the month, mm to see minutes!) :
strvalue = __toString(__toString(ocurrentattribute.GetValue(true))); if (strtypeo == "Time of generation") { strdate = new Date(strvalue); formatter = new java.text.SimpleDateFormat("dd-MM-yyyy"); strdate = new Date(strvalue); strgenerationm = formatter.format(strdate); }