I have a requiremnet, where I have given a year of type string. I want to convert it into date object and add Year, month and days to above date instance.

String callYear = '2014';

Now my requirent is If callYear is '2014' then new date instance must be 15th September of previous year.

Any idea how to achieve that?


A String can be converted into an Integer using Integer.valueOf. Here is an example of how to do that:

String callYear = '2014';
Integer year = Integer.valueOf(callYear);

Once it's an Integer you can convert it to a Date by using Date.newInstance:

Date myDate = Date.newInstance((year - 1), 9, 15);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.