function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cooldamselcooldamsel 

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??????

 

Best Answer chosen by Admin (Salesforce Developers) 
cooldamselcooldamsel
I got the solution. I created another date field and assigned my initial value to it. And in the loop added the count.

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

RavitejaRaviteja

Remove the Spaces inbetween.

 

And also make it as solution if it was worked for you..

cooldamselcooldamsel
No.. It is not because of the space. I tried without the space, it didn't work..
RavitejaRaviteja
share the total controller..
cooldamselcooldamsel
I got the solution. I created another date field and assigned my initial value to it. And in the loop added the count.

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);
}
This was selected as the best answer