Created
February 10, 2015 07:35
-
-
Save michaelrepper/38087fb2784174f5b6c7 to your computer and use it in GitHub Desktop.
r/Dailyprogrammer Challenge #201 Easy
This file contains 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
################################################## | |
# r/Dailyprogrammer Challenge #201 Easy # | |
# coded by Michael Repper # | |
# query [a * t ] gridoodle [ d * o * t ] com # | |
################################################## | |
##################################################################################### | |
# Takes 1 or 2 dates as parameters. The dates should strings be in the format: # | |
# "YYYY-mm-dd" "YYYY-mm-dd" OR "YYYY-mm-dd" # | |
# If only one date is supplied, the days are calculated from the current date. # | |
# If two days are supplied, it calculates the days between them. # | |
##################################################################################### | |
function days_from () | |
{ | |
if [ $# -gt 1 ] | |
then | |
date_1=($1) | |
date_2=($2) | |
else | |
date_1=`date +%Y-%m-%d` | |
date_2=($1) | |
fi | |
result=$(echo $((($(date -d $date_1 +'%s') - $(date -d $date_2 +'%s'))/60/60/24))) | |
if [[ $result -lt 0 ]] | |
then | |
((result*=-1)) | |
fi | |
echo $result "days from" $date_1 "to" $date_2 | |
} | |
days_from "2012-01-01" "2019-10-12" | |
days_from "2020-01-01" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment