I am trying to find the difference between two dates in seconds, by taking the first 10 digits of the file name itself, which I have done as shown below:
However what I am stuck with is that the file I want to return the date from, in the name it has the date and time of last execution, I tried to do the same way but this failed.
Please elaborate how you did "do the same way", and also post the way "this failed".
Where and how is that file name stored? A shell variable? In a loop?
Are you aware that date -d @1489662376 +%s is a NoOP?
So first of all i'm not sure what you mean by a NoOP?
& by meaning same process I mean taking the first 10 digits but as there are "-" between day month year etc it won't except, is there another way to execute this?
So yes I have just noticed that this is a no operation, so I want to find the difference between the dates with two files and have a round number (if possible in minutes/seconds)
So for example to days date = date = Tue Apr 4 11:05:18 BST 2017
The date of the particular file = date -d @1489662376 = Thu Mar 16 11:06:16 GMT 2017
Is there away to calculate the difference in minutes or seconds in this case would be roughly 27,359 minutes or 1,641,542 seconds. Is there a way to get this answer?
See package dateutils, which can be found in many repositories, and includes ddiff :
NAME
ddiff - Compute duration from DATE/TIME (the reference date/time) to
the other
SYNOPSIS
ddiff [OPTION]... DATE/TIME [DATE/TIME]...
DESCRIPTION
Compute duration from DATE/TIME (the reference date/time) to the other
DATE/TIMEs given and print the result as duration. If the other
DATE/TIMEs are omitted read them from stdin.
...
Time specs:
%H Durations in hours
%I Equivalent to %H
%M Durations in minutes
%S Durations in seconds
...
Some additional details:
dateutils.ddiff Compute duration from DATE/TIME (the reference date/ti... (man)
Path : /usr/bin/dateutils.ddiff
Version : 0.3.1
Type : ELF 64-bit LSB shared object, x86-64, version 1 (S ...)
Help : probably available with -h,--help
Home : https://github.com/hroptatyr/dateutils
The package utilities take some practice to learn, but are very useful for dealing with almost any form of date and time data.