Apex で、閏年などにも対応している、当日の 2 か月前の日付を取得する関数を教えてください。
Apex コードを使用した場合は、date 型の静的メソッドを使用することが可能となります。
以下に、当日の 2 か月前の日付を取得するサンプルコードを紹介いたします。
date myDate = date.today();
date NewDate = myDate.addMonths (-2);
system.debug('### Date = '+string.valueof(NewDate));
詳細については、下記のリファレンスをご確認ください。
Date クラス
000385320

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.