Created
November 8, 2025 01:44
-
-
Save jdrews/1917cb6646fea6a0c48d7ecfcaf1bab1 to your computer and use it in GitHub Desktop.
calculate the age of a system using datediff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| INSTALL_DATE=$(stat -c %w /) | |
| NOW_DATE=$(date "+%Y-%m-%d %H:%M:%S") | |
| echo "System installed at $INSTALL_DATE" | |
| # Format 1: days, hours, minutes, seconds | |
| DAYS_DIFF=$(datediff -f "%d days, %H hours, %M minutes, %S seconds" "$INSTALL_DATE" "$NOW_DATE") | |
| echo "Days since installation: $DAYS_DIFF" | |
| # Format 2: years, months, days, hours, minutes, seconds | |
| FULL_DIFF=$(datediff -f "%y years, %m months, %d days, %H hours, %M minutes, %S seconds" "$INSTALL_DATE" "$NOW_DATE") | |
| echo "Years/Months since installation: $FULL_DIFF" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment