I have an upcoming deadline on Nov. 1st, 2011, and I want to print the days until the deadline every time I open Terminal on my MacBook Pro. I've added this to my .profile
:
python -c "from datetime import date; print '%s days until deadline.' % (date(2011,11,1) - date.today()).days"
And this prints 146 days until deadline.
whenever I create a new Terminal window.
This solves my need, but I'm wondering what the one-liner looks like in other languages, or if there are ways to use bash or standard posix command line tools to do the same task.
date command is used to display the system date and time. date command is also used to set date and time of the system. By default the date command displays the date in the time zone on which unix/linux operating system is configured.
To format date in DD-MM-YYYY format, use the command date +%d-%m-%Y or printf "%(%d-%m-%Y)T\n" $EPOCHSECONDS .
Sample shell script to display the current date and time #!/bin/bash now="$(date)" printf "Current date and time %s\n" "$now" now="$(date +'%d/%m/%Y')" printf "Current date in dd/mm/yyyy format %s\n" "$now" echo "Starting backup at $now, please wait..." # command to backup scripts goes here # ...
echo $(expr '(' $(date -d 2011/11/1 +%s) - $(date +%s) + 86399 ')' / 86400) " days until deadline"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With