DateTime型か文字列かを条件分岐にかけたいのですが、文字列は動的なため、日付かどうかで判断させたいです。
どうしたら「日付だったら」もしくは「日付じゃなければ」を判断させられるでしょうか。
Question: I want to apply a conditional branch to a DateTime type or a character string, but since the character string is dynamic, I want to determine whether it is a date.
How can you tell if it’s a date or if it’s not a date?
Answer: Example: String = 15/01/2020.
if String.Contain(“/”)
Then this is date string.
if no “”/" in the string the it will be definitly a character or number string.
Hope my inputs are useful. please mark as completed if you satify.
日付形式には、「/」または最大10文字の長さが含まれます。
例:String = 15/01/2020。
if String.Contain( “/”)
次に、これは日付文字列です。
文字列に「/」がない場合は、文字または数字の文字列になります。
入力が役立つことを願っています。 満足したら完了としてマークしてください。
こんにちは
元のデータ列のフォーマットにも依存しますが、オーソドックスな方法としてDateTime.TryParseメソッドの方法の例を下記添付します。
この方法は実際に変換可否を判断し、その結果をBoolean変数(下記例の場合isDateTime)で返すとともに、変換可能な場合は、変換したDateTime型の値をあわせて返してくれます(下記例の場合dt)。
この後処理でIfの条件でBoolean変数(isDateTime)を使えば、条件分岐できます。
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.