0

This is my first shell script and I need some help.

The shell script needs to extract specific rows from the table based on startingTime column. The startingTime column has time in this format '2016-05-16T13:12:22.089EDT.

Now, I am able to connect to db(supports SQL) via the script able to fetch the data using the below query:

select a,b from table1;

however, I need to change it this format:

select a,b from table1 where startingTime >(NOW() - 2 hours)

however, it doesn't work.

Note:

I tried the below URL trying to use date in specific format but didnt help.

How to compare two DateTime strings and return difference in hours? (bash shell)

Also, I tried the below option using DATE_SUB, didn't help.

MySQL: Fetching rows added last hour

Community
  • 1
  • 1
learner
  • 84
  • 2
  • 13

1 Answers1

0

Following changes worked:

dt2=`date -v-120+%Y-%m-%dT%H:%M:%S.M`

and

select a,b from table1 where startingTime > '$dt2';
learner
  • 84
  • 2
  • 13