You need to sign in to do that
Don't have an account?
myat myat
Date.monthsBetween
Date.monthsBetween method returns one day less. Is it how date method working?
eg.
date fDate = date.newInstance(2018, 09, 01);
date sDate = date.newInstance(2018, 09, 30);
system.debug(fDate.monthsBetween(sDate));
Thanks.
Myat
eg.
date fDate = date.newInstance(2018, 09, 01);
date sDate = date.newInstance(2018, 09, 30);
system.debug(fDate.monthsBetween(sDate));
Thanks.
Myat
GO to setup --> find company infomrmation ..
This link can help you https://success.salesforce.com/answers?id=90630000000CyvHAAS
The result of your code will return you a Zero value as both the dates are of the same month.
If you replace the Date.monthsBetween with Date.daysBetween then you will notice that the
code is 100% correct and you can go with it.
Have a look at this code:
public class Dateclass {
public static void checkdate()
{
date fDate = date.newInstance(2018, 09, 01);
date sDate = date.newInstance(2018, 09, 04);
system.debug(fDate.daysBetween(sDate));
}
}
OUTPUT:
29
I hope you this explanation will help you. Please mark it as best answer if you find it helpful.
Thanks.
Ajay Dubedi
Thanks guys for the suggestion.
Regards,
myat