Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Created February 8, 2023 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxfight3r/1c11479813bc5ec48fd2e5e648c43384 to your computer and use it in GitHub Desktop.
Save tuxfight3r/1c11479813bc5ec48fd2e5e648c43384 to your computer and use it in GitHub Desktop.
bash calculate time elapsed between two date timestamps
#!/bin/bash
date1="2023-02-08 10:50:33"
date2="2023-02-08 14:10:33"
date1_seconds=$(date -d "$date1" +"%s")
date2_seconds=$(date -d "$date2" +"%s")
duration=$(( $date2_seconds - $date1_seconds ))
echo "Time Elapsed: $(($duration/3600)) hours $(($duration %3600 / 60)) minutes and $(($duration % 60)) seconds."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment