Search code examples
shellunixunix-timestamp

Is there any shell script which provide me the time difference in minute between received UNIX timestamp and current date-time


I am getting a timestamp for my search and I am converting it using the command date -d@<timestamp> +"%F %H:%M:%S. It is providing me the Date and Time correctly, i.e. yyyy-mm-dd H:M:S format but I need to find the time difference (in minutes) between the date-time obtained from timestamp and the current date-time.


Solution

  • Use

    date +%s

    to obtain the current time as a timestamp (seconds from THE EPOCH). Since a unix timestamp is simply a number (of seconds since 1970), you can subtract the two timestamps and divide by 60 to obtain minutes.

    If your date command does not support %s, then Biffen comment is helpful.