Skip to content

Instantly share code, notes, and snippets.

@jdrews
Created November 8, 2025 01:44
Show Gist options
  • Select an option

  • Save jdrews/1917cb6646fea6a0c48d7ecfcaf1bab1 to your computer and use it in GitHub Desktop.

Select an option

Save jdrews/1917cb6646fea6a0c48d7ecfcaf1bab1 to your computer and use it in GitHub Desktop.
calculate the age of a system using datediff
#!/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