今日の月を頭の0を除いて取得したい

皆さん、こんにちは。今日の月を頭の0を除いて取得したいのですが。
DateTime.Now.Date.toString(“MM”) だと 04と返り
DateTime.Now.Date.toString(“M”) だと April 13
と返ってしまいます。単に4とだけ取得したいのですが。
よろしくお願いします。

1 Like

Hi @Katsu_Take

I have created a sample workflow for you. I have taken the month as string and converted it to Int32. So that it will remove the leading zero :slight_smile:

RemoveZeroFromMonth.xaml (4.4 KB)

The next workflow, which I have created to simulate how to remove leading zeros from string variables. In case you need to have the month variable as string, you can apply this logic to remove the leading zero from the month variable.

RemoveLeadingZero.xaml (4.5 KB)

If this works out for you, please mark the answer as the solution so that it could help others who are looking for a similar solution… :slight_smile:

----- Translation (Google Translate) ------
こんにちは @Katsu_Take

サンプルワークフローを作成しました。月を文字列として受け取り、それをInt32に変換しました。そのため、先頭のゼロを削除するようになります :slight_smile:

RemoveZeroFromMonth.xaml (4.4 KB)

次のワークフローは、文字列変数から先頭のゼロを削除する方法をシミュレートするために作成しました。月変数を文字列として保持する必要がある場合は、このロジックを適用して月変数から先行ゼロを削除できます。

RemoveLeadingZero.xaml (4.5 KB)

これがあなたのために働くならば、それが解決策としてその答えをマークしてください。それは同様の解決策を探している他の人を助けることができるでしょう… :slight_smile:

Mr.Lahiru.Fernando

Thank You!!

回答ありがとうございました。
一つ目は実行すると下記のエラーが出ます。
式 “CurrentDate” の処理中にコンパイル エラーが発生しました。
Option Strict On で ‘Integer’ から ‘String’ への暗黙の型変換はできません。
どこが間違っているのでしょう?

二つめは、DefaultValueの"009"をDateTime.Now.Date.toString(“MM”)に変更したらうまくいきました。

一つめの修正点を教えてください。

I tested my first solution again. It runs without a problem for me. DId you change the data type?

This is my configuration and it runs and displays 4 in the message box

私は最初の解決策をもう一度テストしました。問題なく動作します。データ型を変更しましたか?

これは私の設定で、実行されてメッセージボックスに4を表示します。


image

私はその理由を調べることができるようにあなたがワークフローを共有することは可能でしょうか?

Mr.Mr.Lahiru.Fernando
Thank You!!
特に変数の型の変更はしていません。ダウンロードしたファイルをそのまま開きました。
1


ワークフローを共有するにはどうしたらよいのでしよう?

Try this one and see…

In the message box, I have changed the code as CurrentDate.ToString. This will convert the int variable to string. This will work for you :slight_smile:

これを試してみてください…

メッセージボックスで、コードを CurrentDate.ToStringに変更しました。これはint変数を文字列に変換します。これはあなたのために働くでしょう

RemoveZeroFromMonth.xaml (4.5 KB)

If this work, please make sure to mark the answer as the solution :slight_smile:
この作品であれば、答えを解決策としてマークしてください :slight_smile:

Mr.Lahiru.Fernando

Thank You!!
正常に動作しました。ありがとうございました。

Hello @Katsu_Take

Anyone searching for such a workflow can easily find it by marking it as a solution, so be sure to mark the correct answer as a solution

こんにちは @Katsu_Take

そのようなワークフローを検索する人は誰でも簡単に解決策としてマークすることで簡単に見つけることができるので、正しい答えを解決策としてマークするようにしてください…

Mr.Lahiru.Fernando

Thank You!!

正しい答えを解決策としてマークする
には、どうしたらよいのですか?

たぶん、もう少し簡単に解決できます。

上記によると、
単一文字(M)だけを使う場合には「%」をはさみなさい、ってことが記載されています。
月だけを使用する場合には、こんな感じですかね。
image

私の環境では、これで「4」だけがログに表示されています。

6 Likes

yukino さん 回答ありがとうございました。
こちらの方が簡単ですね。応用も利きますね。
こちらを採用です。どうもありがとうございました。

@Katsu_Take Try this
DateTime.Now.ToString.Substring(1)

there is a option Beside Heart Emoji

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