0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Modelerデータ加工Tips#08コード

Last updated at Posted at 2021-05-14

Modelerデータ加工TIPS#08 サンプルコード

Nヶ月後の日付を求めるフィールド作成

Clem式
if datetime_month(起算日)+6 > 12
 # Nヵ月後が次の年になる場合
 then if member(datetime_month(起算日) +6-12, [4 6 9 11]) and datetime_day(起算日) = 31
  # 小の月
  then datetime_date(datetime_year(起算日)+1, datetime_month(起算日)+ 6 -12, 30)
  else if datetime_month(起算日)+6-12 = 2 and member(datetime_day(起算日), [29 30 31])
   then if (datetime_year(起算日)+1) rem 4 = 0 and ((datetime_year(起算日)+1) rem 100 /= 0 or (datetime_year(起算日)+1) rem 400 = 0)
    # 2月うるう年
    then datetime_date(datetime_year(起算日)+1, 2, 29)
    # 2月平年
    else datetime_date(datetime_year(起算日)+1, 2, 28)
   endif
   # 大の月
   else datetime_date(datetime_year(起算日)+1, datetime_month(起算日)+6-12, datetime_day(起算日))
  endif
 endif
 # Nヵ月後が年内の場合
 else if member(datetime_month(起算日)+6, [4 6 9 11]) and datetime_day(起算日) = 31
  # 小の月
  then datetime_date(datetime_year(起算日), datetime_month(起算日)+6, 30)
  else if datetime_month(起算日)+6 = 2 and member(datetime_day(起算日), [29 30 31])
   then if datetime_year(起算日) rem 4 = 0 and (datetime_year(起算日) rem 100 /= 0 or datetime_year(起算日) rem 400 = 0)
    # 2月うるう年
    then datetime_date(datetime_year(起算日), 2, 29)
    # 2月平年
    else datetime_date(datetime_year(起算日), 2, 28)
   endif
   # 大の月
   else datetime_date(datetime_year(起算日), datetime_month(起算日)+6, datetime_day(起算日))
  endif
 endif
endif

Modelerデータ加工TIPS#08 サンプルコード2

パラメータを使ってスーパーノード化する場合

Clem式
if datetime_month(起算日)+'$P-month' > 12
 # Nヵ月後が次の年になる場合
 then if member(datetime_month(起算日)+'$P-month'-12, [4 6 9 11]) and datetime_day(起算日) = 31
  # 小の月
  then datetime_date(datetime_year(起算日)+1, datetime_month(起算日)+'$P-month'-12, 30)
  else if datetime_month(起算日)+'$P-month'-12 = 2 and member(datetime_day(起算日), [29 30 31])
   then if (datetime_year(起算日)+1) rem 4 = 0 and ((datetime_year(起算日)+1) rem 100 /= 0 or (datetime_year(起算日)+1) rem 400 = 0)
    # 2月うるう年
    then datetime_date(datetime_year(起算日)+1, 2, 29)
    # 2月平年
    else datetime_date(datetime_year(起算日)+1, 2, 28)
   endif
   # 大の月
   else datetime_date(datetime_year(起算日)+1, datetime_month(起算日)+'$P-month'-12, datetime_day(起算日))
  endif
 endif
 # Nヵ月後が年内の場合
 else if member(datetime_month(起算日)+'$P-month', [4 6 9 11]) and datetime_day(起算日) = 31
  # 小の月
  then datetime_date(datetime_year(起算日), datetime_month(起算日)+'$P-month', 30)
  else if datetime_month(起算日)+'$P-month' = 2 and member(datetime_day(起算日), [29 30 31])
   then if datetime_year(起算日) rem 4 = 0 and (datetime_year(起算日) rem 100 /= 0 or datetime_year(起算日) rem 400 = 0)
    # 2月うるう年
    then datetime_date(datetime_year(起算日), 2, 29)
    # 2月平年
    else datetime_date(datetime_year(起算日), 2, 28)
   endif
   # 大の月
   else datetime_date(datetime_year(起算日), datetime_month(起算日)+'$P-month', datetime_day(起算日))
  endif
 endif
endif
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?