0

I need to write a script:

startdate = 2016-02-14 20:10:10 
enddate =   2016-02-14 23:59:59
c= 1240 (minutes)
d=10  

r = ratio(startdate - enddate) / c;

d=d*r;

How to calculate the difference between the start date and the end date?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
AAA
  • 13

1 Answers1

3

To calculate seconds between two times:

#!/bin/bash

START="2016-02-14 20:10:10"
END="2016-02-14 23:59:59"

SECS=$(echo $(date -d "$END" +%s) - $(date -d "$START" +%s) | bc)

echo $SECS
  • I dont know the ratio of the start and end date is same as $(echo $(date -d "$END" +%s) - $(date -d "$START" +%s)

    what is | bc in the script ?

    can you please confirm me Sorry if i am asking wrong question

    – AAA Oct 26 '16 at 14:01
  • hello my c value is minutes, I want to take the ratio of startdate-enddate then that would be divide by c minutes – AAA Oct 26 '16 at 14:10
  • Why the construct SECS=$(echo $(some command pipeline))? It would be far better to use SECS=$(some command pipeline) and avoid a layer of complication. – Chris Davies Oct 26 '16 at 14:15