![]() |
|
|
|
|
|||||||
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how do you get input of a file to calculations | nadman123 | Shell Programming and Scripting | 6 | 04-11-2008 12:14 AM |
| Time Calculations | Nysif Steve | UNIX for Dummies Questions & Answers | 5 | 09-14-2007 05:49 AM |
| Non-integer calculations in bash | jeriryan87 | Shell Programming and Scripting | 2 | 06-27-2007 01:17 PM |
| Time difference calculations | satnamx | Shell Programming and Scripting | 1 | 07-26-2006 04:44 AM |
| Float calculations | sharmavr | UNIX for Dummies Questions & Answers | 1 | 07-25-2006 11:18 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
I need to be able to use the current date and calculate 7 days ago to be stored in another variable to be passed to a file in my Unix shell script. I need the date in the following format:
date '+%m/%d/%Y' or 05/16/2006 How do I calculate date minus 7 days or 1 week ago? |
| Forum Sponsor | ||
|
|
|
|||
|
I read through the FAQs and still could not find a solution that works. One solution fails if the date is the 1st, like today (6/1/2006). I think that I'm going to have to go with another selection of using sqlplus to get the date from Oracle.
|
|
||||
|
Quote:
|
|
|||
|
Re: Date Calculations
hi there,
date -d '1 week ago' or date -d '7 days ago' will give the date and time of exactly a week ago. You can use '1 month ago' 'yesterday', '2 hours ago', etc.. For future dates, use 'tomorrow', '2 hours now', '1 week now', etc Any date before/after any time period can be displayed this way. Month=$(date -d '1 week ago' +%m) Day=$(date -d '1 week ago' +%d) Year=$(date -d '1 week ago' +%y) echo $Month "/" $Day "/" $Year |
| Thread Tools | |
| Display Modes | |
|
|
|
The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
|
| 421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash exec bash for loop close_wait command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix dead.letter find grep find null character in a unix file grep multiple lines grep or grep recursive inaddr_any inappropriate ioctl for device ksh if logrotate.conf lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp script snoop unix stale nfs file handle syn_sent tar exclude test: argument expected unix unix .profile unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com vi substitute vi+substitute+end+of+line+character while loop within while loop shell script |