![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare date from db2 table to yesterday's Unix system date | sasaliasim | Shell Programming and Scripting | 8 | 04-24-2008 03:04 AM |
| Perl: Extracting date from file name and comparing with current date | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 12:01 PM |
| date issue-find prevoius date in a patricular format | bsandeep_80 | UNIX for Advanced & Expert Users | 3 | 11-15-2007 04:42 PM |
| Changing Creation Date to a Prespecified Date of a File In Unix | monkfan | UNIX for Dummies Questions & Answers | 4 | 11-28-2006 03:15 AM |
| Substraction in bash | mclaudiu | SUN Solaris | 2 | 11-23-2005 06:00 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
In Unix script, how to get a "date - 1" ie, yesterday?
|
| Forum Sponsor | ||
|
|
|
|||
|
#!/bin/bash
# figure out what yesterday was. date '+%Y %m %d' | { read year month day day=`expr "$day" - 1` case "$day" in 0) month=`expr "$month" - 1` case "$month" in 0) month=12 year=`expr "$year" - 1` ;; esac day=`cal $month $year | grep . | fmt -1 | tail -1` esac echo "Yeseterday was: $day $month $year" } |
|
|||
|
in Perl there is really handy way to manipulate Date
print scalar localtime (time() - 86400 * n); it will substract n from current date and print the date print scalar localtime (time() - 86400 * 1); #yesterday print scalar localtime (time() - 86400 * 30); #Date of 30 days back To get date four days from now print scalar localtime (time() + 86400 * 4); and so on.... |
|||
| Google UNIX.COM |