|
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
|
|||
|
|||
|
getting previous day.
Hi,
i am developing a script for my project. In my script i need to check some conditions based upon some values. in that one value is the previous date. with the previous date i need to check and process some values. I have a function with me retrieve the yesterdays date. But now i have a scenario that i need to check with the yesteday day alone. That is say for example today is Thu,i need to check one day before that is with Wed. i am not sure how to retrieve this Thu-1. I am trying `date %a -1` but its not working. Please help me in this. Thanks, Raju |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
|
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Try this, Code:
date -d "1 day ago" | cut -d ' ' -f 1 |
|
#4
|
||||
|
||||
|
You can try this,
date +%a -d "1 day ago" This will give the yesterday day name in three letter format.For ex,Wednesday as Wed.If you want full day name,use %A instead of %a. |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
ksh93 include printf extension. Gnu date command include also epoc + calculation extensions. Some bsd date include -r option. Ex. using ksh93 Code:
printf "%T" now More example to use printf and date calculation. Or using gnu date command like Code:
#!/someposixsh epoc=$(date -u +%s) echo $epoc (( yesterday=epoc-86400 )) datestr=$(date -d "1970-01-01 $epoc seconds" ) echo $datestr datestr=$(date -d "1970-01-01 $epoc seconds" '+%Y-%m-%d %H:%M:%S' ) echo $datestr echo "yesterday:" date -d "1970-01-01 $yesterday seconds" '+%Y-%m-%d %H:%M:%S' If using date, read your man date. |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
The following example used for current date from ago Code:
#date
Tue Feb 23 14:32:14 IST 2010
#date -d "1 day ago"
Mon Feb 22 14:32:18 IST 2010
#date -d "1 week ago"
Tue Feb 16 14:32:24 IST 2010
#date -d "1 month ago"
Sat Jan 23 14:32:29 IST 2010
#date -d "1 year ago"
Mon Feb 23 14:32:35 IST 2009The following example used for current date after Code:
#date
Tue Feb 23 14:35:00 IST 2010
#date -d "+1 day"
Wed Feb 24 14:35:05 IST 2010
#date -d "+1 week"
Tue Mar 2 14:35:09 IST 2010
#date -d "+1 month"
Tue Mar 23 14:35:14 IST 2010
#date -d "+1 year"
Wed Feb 23 14:35:21 IST 2011for more information read the date man page. Last edited by ungalnanban; 03-08-2010 at 11:42 PM.. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
YESTERDAY=`TZ=CST+24 date +%Y%m%d`
|
| 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 |
| Get Previous Date | dinjo_jo | Shell Programming and Scripting | 5 | 11-04-2009 10:11 PM |
| previous posts | james6 | Forum Support Area for Unregistered Users & Account Problems | 2 | 06-17-2008 06:31 AM |
| Previous command | new2ss | HP-UX | 5 | 02-14-2008 05:06 AM |
| Get the Previous date | Nayanajith | Shell Programming and Scripting | 2 | 06-29-2006 01:39 AM |
| Value of previous row using awk | videsh77 | Shell Programming and Scripting | 2 | 02-18-2005 12:23 PM |
|
|