![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help, I need to get the last date of previous month | sirrtuan | Shell Programming and Scripting | 11 | 10-14-2008 06:59 AM |
| Specify a previous date as start date in shell script | ritzwan0 | Shell Programming and Scripting | 2 | 09-25-2006 06:58 PM |
| Previous day's date in Perl? | rajus19 | Shell Programming and Scripting | 4 | 07-18-2006 01:40 AM |
| Get the Previous date | Nayanajith | Shell Programming and Scripting | 2 | 06-29-2006 02:39 AM |
| How to find Previous date and Coming date | arunava_maity | UNIX for Dummies Questions & Answers | 2 | 05-24-2001 12:41 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How would I go about getting the previous date on the server? I'm out of ideas...I am thinking that I could do it using the date command, but I am unable to find any information on doing it. For example if the current date is April 17th 2008 it would be (20080417) <- (YYYYMMDD). I need the previous date which is April 16th 2008 stored in the following format (20080416) <- (YYYYMMDD). I breifly thought that I could just subtract 1 from the day (DD) amount, but the only problem is what if it is the 1st of the month, I would then be unable to tell if it should be the 30th, 31st, or even the 29th? Please help. Thanks all
![]() |
|
||||
|
If you have gnu date or install the gnu version of date it will do that.
If you care to install ksh93 instead of ksh88 it will do that. The only other option is to write a fairly large piece of shell code. Go to the FAQ - look for Perderabo's 'Date Arithmetic' thread. There are examples there. |
|
||||
|
Code:
#!/usr/bin/ksh YESTURDAY=`TZ=EST+24 date +%Y%m%d` echo $YESTURDAY Note: if your timezone is something other than EST5DST just put in what your's is and it should work just fine. Some OS's you can change more than 1 day, HP-UX one day is as far as you can go with this approach. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|