How do I find the difference between two dates in Linux?

How do I find the difference between two dates in Linux?
Answer
  1. Provide valid time string in A and B.
  2. Use date -d to handle time strings.
  3. Use date %s to convert time strings to seconds since 1970 (unix epoche)
  4. Use bash parameter expansion to subtract seconds.
  5. divide by seconds per day (86400=60*60*24) to get difference as days.
  6. ! DST is not taken into account ! See this answer at unix.
13 мар. 2015 г.
 

Tìm kiếm

Back
Top