You need to sign in to do that
Don't have an account?
Urgent !!!!!!!! Auto increment date of the date field
Hi All,
I have a date field that is obtained as user input. I need to dispaly a report that contains the count of certain value for each date. So am auto incrementing the date of the date field. After incrementing the field, i have to assign the value to the same field. But am getting wrong incremented values.
I have assigned a field called start date.
Date startDT=Date.newInstance(2013, 8, 15); -- 2013-08-15 00:00:00
Then within the for loop am incrementing the day of the field and assigning to the same filed...
startDT = startDT.addDays(1);
When i use debug and get the output, the startDT value changes to 2013-12-12 00:00:00.
I don't know what mistake i have done. Can anyone please help me??????
Date startDT=Date.newInstance(2013, 8, 15);
Date NewStartDate;
NewStartDate = startDT;
for(integer i=1; i<=31; i++)
{
DateTime ReqmtAssignDt=ReqmAssignUser.createddate;
Date ReqmAssignDate=Date.NewInstance(ReqmtAssignDt.year(), ReqmtAssignDt.month(), ReqmtAssignDt.day());
if(ReqmAssignDate == NewStartDate)
{
count ++;
System.Debug('Count:' +count);
}
NewStartDate = startDT.addDays(i);
}
All Answers
Remove the Spaces inbetween.
And also make it as solution if it was worked for you..
Date startDT=Date.newInstance(2013, 8, 15);
Date NewStartDate;
NewStartDate = startDT;
for(integer i=1; i<=31; i++)
{
DateTime ReqmtAssignDt=ReqmAssignUser.createddate;
Date ReqmAssignDate=Date.NewInstance(ReqmtAssignDt.year(), ReqmtAssignDt.month(), ReqmtAssignDt.day());
if(ReqmAssignDate == NewStartDate)
{
count ++;
System.Debug('Count:' +count);
}
NewStartDate = startDT.addDays(i);
}