APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Setdate

The Unix/Linux "date" command will display or set the current date and time, but ordinary folks find its syntax confusing. I wrote a little script that tries to make it a little less geeky.

The "setdate" is just a more user-friendly front end to changing the date and time:



echo -n "Enter Date or leave blank for `date +%m/%d/%y`: " 
read mydat
echo -n "Enter Time or leave blank for `date +%H:%M`: " 
read mytime
if [ "$mydat" != "" ]
then
      mmdd=`echo $mydat | sed 's/\///g;s/..$//'`
      yr=`echo $mydat | sed 's/\///g;s/^....//'`
else
      mmdd=`date +%m%d`
      yr=`date +%y`
fi

if [ "$mytime" != "" ]
then
      newtime=`echo $mytime | sed 's/://g'`
else
      newtime=`date +%H%M`
fi
date "$mmdd$newtime$yr"

This script works on Linux, SCO and most other Unixes.

Publish your articles, comments, book reviews or opinions here!



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> User Friendly Date Script



Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us