データテーブルの時間を比較したい

いつもお世話になっております。
以下のようなデータテーブルで、列「時刻」の時刻を前後の行と比較し、
15分以上差がある場合、列「チェック」へNGと記載、
差が15分未満の場合、列「チェック」へOKと記載したいです。
image

希望完成形
image

どのように作成すれば良いのか教えて頂きたくよろしくお願い致します。

Hi @miwa_yamamoto

You need to first read the data into datatable using read range activity
Then use a loop to loop through all the rows…’
Make sure you add condition for checling first and last row differently as they wont have previous and next values respectively.
To get row count dt.rows.count will give you that

Now for your comparision use Datediff(dateinterval.minutes,time1,time2) it will give you difference between time in minutes then you can compare with any number of minutes and update the column accordingly

For converting time string to datetime use datetime.parseexact(time1,”hh:mm”,system.globalization.culturalinfo.invariantculture)

For first row compare only next date and for last row compare only previous row you can do this by adding if condition and check if the loop count

Cheers

1 Like

こんにちは

ルールがわかりにくいのですが、例えば2行目の場合は1行目、3行目どちらかが15分以内ならOKでしょうか?
4行目は前後いずれも15分以内ではないので、NGではないでしょうか?

1 Like

いつもありがとうございます。
ルールの説明が悪く申し訳ございません。
また、ご指摘通り、ルールの説明が1つ抜かっておりました。

前後の行より15分以内の場合はOK
:arrow_right:2行目の場合は1行目、3行目どちらかが15分以内であればOK

抜かっていたルール
12:00 もしくは、 12:45付近の時間であれば、その時間から15分以内であればOK

となっております。

こんにちは

以下いかがでしょうか?

条件(実際は改行を削除してください)

(idx>0 AndAlso Math.Abs((DateTime.Parse(CurrentRow("時刻").ToString)-DateTime.Parse(dt.Rows(idx-1)("時刻").ToString)).TotalMinutes)<=15)
 OrElse (idx<dt.Rows.Count-1 AndAlso Math.Abs((DateTime.Parse(CurrentRow("時刻").ToString)-DateTime.Parse(dt.Rows(idx+1)("時刻").ToString)).TotalMinutes)<=15)
 OrElse (DateTime.Parse(CurrentRow("時刻").ToString).ToString("HH:mm")>="11:45" AndAlso DateTime.Parse(CurrentRow("時刻").ToString).ToString("HH:mm")<="12:15")
 OrElse (DateTime.Parse(CurrentRow("時刻").ToString).ToString("HH:mm")>="12:30" AndAlso DateTime.Parse(CurrentRow("時刻").ToString).ToString("HH:mm")<="13:00")

Sample20221114-5.zip (10.1 KB)

1 Like

Yoichi様
いつもありがとうございます。
1つの式であんなにも沢山のことが言い表せるのですね。
本当にありがとうございます。
お陰様で無事にできました。

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