Are you writing your own code or are you using out of the box product?
Can you use PI DataLink Compress Data with following filter expression to see the timestamps?
It only shows events that is different value from previous value.
If you want to see only value = 1 or 2, then filter expression can be following.
'tag' <>prevval('tag') and ('tag' =1 or 'tag' = 2)
In addition to what Kenji suggested, there are quite a lot of ways to go about this.
For example, if you are working on a custom application, there are ways to do it with code; if you are looking to display this information on a ProcessBook dashboard, you could set up a Picalc to record this information, etc etc. If you let us know your use case, we will be able to give you better information.