Created
April 25, 2020 22:36
-
-
Save seanr/af640f0bf94ba84e5b0a99933480dbc2 to your computer and use it in GitHub Desktop.
Simple fish shell command to give a daycount between YYYY-MM-DD and now.
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
# Print the number of days between a given date or the default date and the current date. | |
# | |
function daycount | |
# Default date. | |
set DATE "2020-02-17" | |
# Test for presence and formatting of argument. | |
if count $argv > /dev/null | |
if string match -qr '^([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))$' $argv | |
set DATE $argv | |
else | |
echo "Date must be in YYYY-MM-DD format." | |
return 1 | |
end | |
end | |
set ELAPSED (php -r "echo date_diff(date_create('$DATE', new DateTimeZone('America/New_York')),date_create('now', new DateTimeZone('America/New_York')))->format('%a');") | |
echo "Elapsed: $ELAPSED days" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment