I am trying to compare two timestamps and if x is greater than y then do some action. I tried it with bash on my Linux machine but I get an error "invalid date" here is my code:
#!/bin/bash
x='2020.01.23 14:41:18.554'
y='2020.01.23 17:17:02.323'
if [[ $(date -d "$x") -gt $(date -d "$y") ]]
then
echo -e "first value is greater than second"
#### Perform some actions
#### Perform some actions
else
echo "second value is greater, so do nothing"
fi
exit
when I run the script, I get below errors
date: invalid date `2020.01.23 14:41:18.554'
date: invalid date `2020.01.23 17:17:02.323'
I tried converting the whole value to epoch time and then compare, but in epoch time, milliseconds are not counted. How can get this comparison right including the milliseconds? Thank you.