dateutils icon indicating copy to clipboard operation
dateutils copied to clipboard

Human readable datediff: "2 days ago"

Open minfrin opened this issue 2 years ago • 1 comments
trafficstars

Is there a way to show human readable date differences?

Most specifically, given the expiry date of a certificate, I can get raw output of number of days until expiry or after expiry, positive or negative.

Is there a way to provide separate formats for positive results (eg "Expires in $d days"), exact results (eg "Expires today), and negative results (eg "Expired 2 days ago")?

minfrin avatar Aug 22 '23 11:08 minfrin

Hi, no there is not. Can you maybe use awk to do what you desire?

$ echo 4 | awk '$0 = $1 > 0 ? "Expires in "$1" days" : $1 < 0 ? "Expired " ""-$1" days ago" : "Expires today"'
Expires in 4 days

$ echo -4  | awk '$0 = $1 > 0 ? "Expires in "$1" days" : $1 < 0 ? "Expired " ""-$1" days ago" : "Expires today"'
Expired 4 days ago

hroptatyr avatar Aug 22 '23 11:08 hroptatyr