Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you print the days until a deadline from the command line?

Tags:

date

bash

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.

like image 918
jwhitlock Avatar asked Jun 08 '11 16:06

jwhitlock


People also ask

Which command used to print date and time in terminal?

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.

How do you display 2 days back date in dd mm yyyy format in Linux?

To format date in DD-MM-YYYY format, use the command date +%d-%m-%Y or printf "%(%d-%m-%Y)T\n" $EPOCHSECONDS .

How do I print the date and time in Shell?

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 # ...


1 Answers

echo $(expr '(' $(date -d 2011/11/1 +%s) - $(date +%s) + 86399 ')' / 86400) " days until deadline"
like image 161
Chris Dodd Avatar answered Oct 12 '22 23:10

Chris Dodd