DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Find index of timestamp

Solved!
Go to solution

Hi,

 

I have a Channel which contains Timestamps like every second:

TLG90_0-1691624410874.png

then there are files that contain a picture and the name of the date the picture was taken:

1_20230324-121409.png

 

now I need to search through the timestamps to find the index closest to the day, the picture was taken.

In this example there are the values: 

TLG90_1-1691624539872.png

so the one in the middle would make it. 

milli/microseconds aren't really important.

 

I just don't get an approach to this.

I'm able to create a datetime.datetime variable with the values out of the filename. 

But afterwards I'm unable to seach for that date in the timestamp.

And I need the index of that timestamp, because I need a value of another channel with that index.

 

Does anyone have an approach for me?

 

Thanks in advance.

 

 

 

 

0 Kudos
Message 1 of 4
(1,555 Views)

Not a diadem users, but if you subtract the search time from the array of times and take the absolute value, the smallest value will give you the index of the closest entry.

0 Kudos
Message 2 of 4
(1,530 Views)
Solution
Accepted by topic author TLG90

Hello,

 

you can find the index to the nearest value with the function PNo.

 

dim Index
Index = PNo("[1]/Time_Stamp", TTR("20230324-121409", "#yyyymmdd-hhnnss"))
LogFileWrite("Index: " & Index)

 

Regards

Message 3 of 4
(1,500 Views)

Thanks a lot, didn't know that PNo exists.

It's exactly what I was looking for.

0 Kudos
Message 4 of 4
(1,459 Views)