How do you get the Day value of a Date Field?
Subject: umm…
Day
Returns the day of the month (an integer from 1 to 31) for a date/time argument.
Subject: getDay() is not working
How do you get the Day value of a Date Field with Server Side Javascript?
var DateField=currentDocument.getItemValueDate(“ApprovedDate”);
None of the Code below works:
var DayVal=@Day(@Date(DateField));
or
Var DateVal=new Date(DateField));
Var DayVal=DateVal.getDay();
Subject: From the help
Copied straight from designer help, this returns 9 for me (today on the 10th)
var date1 = @Yesterday();
var year = @Year(date1);
var month = @Month(date1);
var day = @Day(date1);
return day
Edit: do for you it would work something like:
ar DateField=currentDocument.getItemValueDate(“ApprovedDate”);
var DateVal=new Date(DateField));
var day = @Day(DateVal);
return day
Subject: I was not clear.
I can get the Day value of the field on the xpage.
I have a FromDate - ToDate.
I trying to loop through the date range and exclude Saturday and Sunday (0 and 6).
I can’t get the getDay() function to work when I loop through the dates.
Here is the Sample of the Code: Please let me know if you can get it to work.
var FromDate=currentDocument.getItemValueDate(“FromDate”);
var ToDate=currentDocument.getItemValueDate(“ToDate”);
Var IncrementDate = FromDate;
if(ToDate!=null){
while (FromDate <= ToDate){
DayVal=IncrementDate.getDay());
if (DayVal!=0 && DayVal!=6)
{
//Add the Date to the List
}
IncrementDate.adjustDay(1);
}}
Subject: Correction
var FromDate=currentDocument.getItemValueDate(“FromDate”);var ToDate=currentDocument.getItemValueDate(“ToDate”);
var IncrementDate = FromDate;
if(ToDate!=null){
while (IncrementDate <= ToDate){
DayVal=IncrementDate.getDay());
if (DayVal!=0 && DayVal!=6)
{
//Add the Date to the List
}
IncrementDate.adjustDay(1);
}}
Subject: Code
OK, yes that’s a different question. Your if statement is wrong, you need to check the increment date, not the from date.
var FromDate=currentDocument.getItemValueDate(“FromDate”);
var ToDate=currentDocument.getItemValueDate(“ToDate”);
Var IncrementDate = FromDate;
if(ToDate!=null){
while (IncrementDate<= ToDate){
DayVal=IncrementDate.getDay());
if (DayVal!=0 && DayVal!=6)
{
//Add the Date to the List
}
IncrementDate.adjustDay(1);
}}
To be honest, I don’t know the exact syntax of ssjs very well, but the above should work in principal, assuming you can compare the dates directly like that