ファイル名を上期,下期で分けたい

条件分岐にてファイル名を4~9月なら上期として。10~3月なら下期として出力したいです。
これは、ファイル名で判定ができるのでしょうか?それとも本日の日付から判定して出せるものになるのでしょうか? 調べてみても本日の日付取得などしか引っかからず
よろしくお願いいたします。

Hi @once10201029

Can you try like below

If fileName.Contains("April") Or fileName.Contains("May") Or fileName.Contains("June") Or
   fileName.Contains("July") Or fileName.Contains("August") Or fileName.Contains("September") Then
   ' This is the first half
ElseIf fileName.Contains("October") Or fileName.Contains("November") Or fileName.Contains("December") Or
   fileName.Contains("January") Or fileName.Contains("February") Or fileName.Contains("March") Then
   ' This is the second half
End If

Or

If Now.Month >= 4 And Now.Month <= 9 Then
   ' This is the first half (April to September)
Else
   ' This is the second half (October to March)
End If

Regards,

1 Like

@once10201029,

I’m assuming you will be able to get the month name from file. Use that month name in below code. Use this code to get month number.

intMonthNumber = CInt(Datetime.ParseExact(input_month ,“MMMM”,System.Globalization.CultureInfo.InvariantCulture).ToString(“MM”))

This will give you month number. Use an If activity after this to determine if it’s first half or second half like this:

intMonthNumber >= 4 and intMonthNumber  <= 9

This is your first half

intMonthNumber >= 10 and intMonthNumber  <= 3

This is your second half

Thanks,
Ashok :slight_smile:

こんにちは

ファイル名にに含まれている日付情報から上期ot下期を出力したいということでしょうか?

そうであれば、基本的には日付情報を抽出し、DateTiemに変換、月を抽出して4以上9以下なら上期です。(月情報の位置が決まっているなら、直接抽出しても良いかもしれません)

intMonth = DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(filename,"\d{8}").Value,"yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture).Month

サンプル
Main.xaml (8.0 KB)

ありがとうございます。
今後作っていく上でお聞きしたいのですが、
intMonth >=4 AndAlso intMonth<=9
このような条件式などはどのように検索して出てくるのでしょうか?
いつも検索の仕方が悪いのか調べてやっていく上でやりたいことがヒットしないことが多く勉強や調べる上でどこかオススメサイトなどあるのでしょうか?

通常この類の内容は検索しても出てこないと思います。
どちらかというと言語要件からロジックへの変換の部分になりますので

上期
→4月から9月
→月の数字が4以上かつ月の数字が9以下
→ intMonth>=4 かつ intMonth<=9
→ intMonth>=4 AndAlso intMonth<=9

のように変換できなければなりません。

個々の変換:例えば「以上」は>= のような部分はまで落とし込めば検索で引っかかりやすいと思います。(条件式 以上 VB.net のようなキーワードで検索)

ありがとうございます。
根本の勉強を精進しようと思います。

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.