current_date -1


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers current_date -1
# 1  
Old 08-14-2007
current_date -1

Hello,
Can someone please help me how do i get current date-1 in a unix script
i.e yesterday's date ?

Thanks,
Sateesh
# 2  
Old 08-14-2007
... by searching the FAQs first.
# 3  
Old 08-14-2007
Bug

Sateesh,

try this command:

date --date='-1day'
# 4  
Old 08-16-2007
hey praveen,

date --date='-1day' is this type of syntax applicable with all flavour of unix....as i tried this it works fine with linux but not sun.....

i think kotasateesh u should go for small shell script....which will works for you irrespective of flavour.
# 5  
Old 08-16-2007
You have to use perl, python, ruby, etc. or C to do that without the gnu date.
Here is a perl example:
Code:
perl -e ' use POSIX qw(strftime); 
           print strftime "%m-%d-%Y\n", localtime(time - 86400);  '

# 6  
Old 08-20-2007
#hence if todays date is 09282001 in mmddyyyy format
dt='09282001'
#now store value of dt to a file
echo $dt>file1
#now cut value of today's date in variable v1
v1=`cut -c3-4 file1`
#now find out value of previous date by using expr command
v2=`expr $v1 -1`
#now prepare the full date by replacing 3rd and 4th chr of file1 by value of v1


#Of course you will also have to add validations for last date of months and #for february also
#hope expr command will help you

Regards,
Siva.P
Bangalore
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question