PappuSingh
(Pappu Kumar Singh)
February 24, 2023, 6:30am
1
Hi,
Please see the below code sample.
long l1=(new Date().getTime());
//emit(l1);
long l= ChronoUnit.SECONDS.between(l1, doc['timestamp'].value);
if(l<=100000){
emit('New')
}
else{emit('Old')}
I am getting the below Error
Cannot cast from [long] to [java.time.temporal.Temporal]. Verify that you have correctly set the runtime field type.
stephenb
(Stephen Brown)
February 24, 2023, 7:00am
2
Hi @PappuSingh Welcome to the community.
Perhaps this will help it is nearly the same use case.
PappuSingh
(Pappu Kumar Singh)
February 24, 2023, 11:17am
3
How I can calculate hours or day?
Please see my code below
long datenow = new Date().getTime();
long datewas = doc['createdTime'].value.getMillis();
long milisecondnd=datenow - datewas;
long second=milisecondnd/1000;
long hours=second/3600;
long daycount=hours/24;
emit(daycount);
the wrong Number is displaying it is showing 1
CreatedTime="Jan 21, 2023 @ 01:29:06.500"
stephenb
(Stephen Brown)
February 24, 2023, 3:22pm
4
Do you want Days in Integer or Float?
Field Type Double
long datenow = new Date().getTime();
long datewas = doc['@timestamp'].value.getMillis();
double days = (datenow - datewas) / 86400000.0;
emit (days);
Field Type Long
long datenow = new Date().getTime();
long datewas = doc['@timestamp'].value.getMillis();
long days = (datenow - datewas) / 86400000;
emit (days);
PappuSingh
(Pappu Kumar Singh)
March 1, 2023, 10:54am
5
Thank you it is working now.
1 Like
system
(system)
Closed
March 29, 2023, 10:55am
6
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.