-2

I have row values as dates in one object, i.e dates within a given year. I have a second object with field names as Day1__c, Day2__c and so on till Day366__c. I want to assign the dates to the fields in the 2nd object.

Example, if the date in the first object is 2018-01-01 I want to assign a value to field Day1__c in the second object and if the date is 2018-12-31 I want to assign a value to Day365__c.

1 Answer 1

2

I hope the dayOfYear() method of Date class can help you to achieve this requirement.

As per Salesforce it "Returns the day-of-year component of a Date." First, you have to get this number (suppose 294) based on the Date from the first object and you can relate the corresponding field in the second object as Day294__c.

date myDate = date.newInstance(1998, 10, 21);
Integer day = myDate.dayOfYear();
system.assertEquals(294, day);
1
  • Thansk Saroj. That was helpful. May 7, 2018 at 4:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .