#!/bin/bash ###################################################################### #Copyright (C) 2018 Kris Occhipinti #https://filmsbykris.com ####BASH Date command examples### #This program is free software: you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation, either version 3 of the License, or #(at your option) any later version. #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. #You should have received a copy of the GNU General Public License #along with this program. If not, see . ###################################################################### wait_line(){ sleep 2 echo "" } echo "Current Date and Time:" date wait_line echo "The current date is:" date +%F echo "or as I write it:" date +%m/%d/%Y echo "But, you might write it:" date +%d/%m/%Y wait_line echo "Today's Day of the Week is:" date +%a echo "or:" date +%A wait_line echo "Current Time:" date +%H:%M:%S wait_line echo "or in 12 format and no seconds:" date +%I:%M wait_line echo "UTC/Unix time (also known as POSIX time or UNIX Epoch time)" echo "Seconds since Thursday, 1 January 1970:" date +%s wait_line echo "Yesterday Was:" date -d yesterday wait_line echo "Tomorrow Will Be:" date -d tomorrow wait_line echo "This Sunday will be:" date -d "Sunday" wait_line echo "Last Sunday was:" date -d last-sunday +%F wait_line echo "Next Sunday will be:" date -d "next-sunday" +%F wait_line echo "1974-01-04 was a:" date -d "1974-01-04" +"%A" wait_line echo "Today is the $(date +%j) day of the year" wait_line echo "Christmas will be on a $(date -d 25-Dec +%A) this year" wait_line TODAY=`date +%j` # Today, as day-of-year (1-366) CHRISTMAS=`date -d 25-Dec +%j` # Christmas day, in same format echo "There are $(($CHRISTMAS - $TODAY)) days until Christmas." wait_line echo "If you really want to find the number of days between two dates" echo "you should use UTC" echo "The CHRISTMAS methode won't work if the dates are in different years" wait_line echo "For example, days between 1/9/1981 and 10/22/1984:" d1="$(date -d "1/9/1981" +%s)" d2="$(date -d "10/22/1984" +%s)" echo "( $d2 - $d1 ) / (24*3600)" | bc wait_line d1="$(date -d "1/9/1999" +%s)" d2="$(date +%s)" #today d="$(echo "( $d2 - $d1 ) / (24*3600)" | bc)" echo "It has been $d days since 1/9/1999" wait_line