業務でよく使う月初日や月末日を算出するサンプルです。下記記事でも作成しましたがもう少し効率にしたものになります。
【PowerAutomate】月初月末等の日付算出について
【PowerAutomate Desktop】月初月末等の日付算出について解説
全体概要
本日日付を取得し月初月末等を算出します。
※下記アクションをコピペすることでフローを作成できます。
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
**REGION システム日時から時刻を切り捨てる
Text.ConvertDateTimeToText.FromDateTime DateTime: CurrentDateTime StandardFormat: Text.WellKnownDateTimeFormat.ShortDate Result=> システム日付
**ENDREGION
**REGION 日付から曜日を取得する
SET 曜日_英 TO CurrentDateTime.DayOfWeek
Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''ddd''' Result=> 曜日_和
**ENDREGION
**REGION 前日・月初・月末・月日数を取得
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> 前日
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 * (CurrentDateTime.Day - 1) TimeUnit: DateTime.TimeUnit.Days ResultedDate=> 月初1
SET 月初2 TO CurrentDateTime.Year + '/' + CurrentDateTime.Month + '/01'
DateTime.Add DateTime: 月初1 TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Months ResultedDate=> 月末
DateTime.Add DateTime: 月末 TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> 月末
SET 月日数 TO 月末.Day
**ENDREGION
日付算出方法について
月初
①システム日時の「日」の1日前を減算します。
②システム日時の「年」と「/」と「日」と「/01」を結合します。
月末
月初の1月後から1日前の日付
月日数
月末の日数を取得します
変数の指定方法について
変数を指定する場合は下図のように変数を展開することで変数の変換が可能です。例えば日付変数から年のみを取得することが可能です。
リンク
コメント