1

On gemfire, I am having one region ABC and within this region there is a column/field of type long. In this field I am setting the value as System.nanoTime(). I want to fetch all the record from this region which is of 24 hour older. How can I do this?

Currently I am trying to make a query as below but its not working.

select  regionTimestamp from /ABCRegion where (((((regionTimestamp-currentTimeStamp)/ 1000000000))/3600)>24)

Any help suggestion must be appreciated.

USB
  • 6,019
  • 15
  • 62
  • 93
Zia
  • 1,001
  • 1
  • 13
  • 25
  • Besides the answers, `currentTimeStamp` will always be later than `regionTimestamp` since that's recorded in the past .Therefore it should be `currentTimeStamp-regionTimestamp` to calculate the delta time instead of the other way around. – Mark Dec 17 '18 at 08:45

1 Answers1

2

NOTE: System.nanoTime() is reset whenever your computer restarts so it's not a good choice to store in a database. This also means the time is local to each machine.

LocalDateTime.now() is a nano second resolution wall clock which doesn't reset on a reboot and is more likely to work across machines.


Never the less, you could rearrange this and calculate

long now = ...
long aDayAgo = now - 86_400_000_000_000L; // 24 hours.

search for ... where regionTimestamp > aDayAgo
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    Would it not be better to use `TimeUnit.NANOSECONDS.toHours(now - regionTimestamp) > 24` or `TimeUnit.HOURS.toNanos(24)` instead of `86_400_000_000_000L` since it's more readable/maintainable? Or is there an advantage to your approach, just curious – Mark Dec 17 '18 at 08:51
  • My concern is that how i would made a query for the gemfire and there is some limitations so i cant change that to LocaldateTime – Zia Dec 17 '18 at 09:41