|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Date time calculation
hello guys,
I had been to many forums and many topics in this site as well for my question but did not get any solution. My question is how i can get y'day date with time stamp today is 20100729103819 and i am looking for output as 20100728103819. in simple words as we do in oracle sysdate-1 (with timestamp). Thanks a lot! |
| Sponsored Links | |
|
|
|
#3
|
|||
|
|||
|
Hi, Code:
date --d "1 day ago" +%Y%m%d%H%M%S |
|
#4
|
||||
|
||||
|
This is GNUism - may not be applicable.
|
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
For non GNU: Code:
date '+%m %d %Y' |
{
read MONTH DAY YEAR
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 "Yesterday was: $MONTH $DAY $YEAR"
}or Code:
OFFSET=${1:-1}
case $OFFSET in
*[!0-9]* | ???* | 3? | 29) print -u2 "Invalid input" ; exit 1;;
esac
eval `date "+day=%d; month=%m; year=%Y`
typeset -Z2 day month
typeset -Z4 year
day=$((day - OFFSET))
if (( day <= 0 )) ;then
month=$((month - 1))
if (( month == 0 )) ;then
year=$((year - 1))
month=12
fi
set -A days `cal $month $year`
xday=${days[$(( ${#days[*]}-1 ))]}
day=$((xday + day))
fi
echo $dayEDIT: My BAD, I didnt see the format you wanted, you will have to modify a little to get your format. |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Time stamp calculation | maverick_here | Shell Programming and Scripting | 6 | 05-17-2009 10:59 PM |
| Time Calculation | bpfoster76 | UNIX for Dummies Questions & Answers | 5 | 02-03-2009 08:58 AM |
| Date Calculation | subhendu81 | Shell Programming and Scripting | 2 | 09-30-2008 01:34 AM |
| Time difference calculation | Segwar | Shell Programming and Scripting | 2 | 07-16-2008 01:59 AM |
| time calculation | liux99 | UNIX for Advanced & Expert Users | 2 | 08-18-2005 10:33 PM |
|
|