[Solved] Using date command, getting previous day

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Using date command, getting previous day
# 1  
Old 01-14-2014
[Solved] Using date command, getting previous day


i need to get previous day using date command.
Can you please help.

sdosanjh:/home>  date +%m%d%y

i tried
-d '-1 day'

but it is not working
# 2  
Old 01-14-2014
If using GNU date:

date --date="1 day ago" 
Mon Jan 13 22:13:43 EST 2014

date --date="yesterday"
Mon Jan 13 22:13:52 EST 2014

This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 01-15-2014
but it shows error.
below is OS

sdosanjh:/home> isainfo -kv
64-bit sparcv9 kernel modules

sdosanjh:/home> date --date="1 day ago"
date: illegal option -- date=1 day ago
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

---------- Post updated at 11:22 PM ---------- Previous update was at 11:21 PM ----------

And want the output from mmddyy to mm(dd-1)yy format

# 4  
Old 01-15-2014
There are some useful links in this post from the FAQ forum:
Yesterdays Date/Date Arithmetic | Unix Linux Forums | Answers to Frequently Asked Questions
This User Gave Thanks to CarloM For This Post:
# 5  
Old 01-15-2014
Ande there is also:
General Purpose Date Script | Unix Linux Forums | Tips and Tutorials

You havent been searching much...
# 6  
Old 01-15-2014
@carloM it worked.

TZ=GMT+24 date "+%m%d%y"


date '+%m:%d:%y' | awk -F":" '{printf"%2d%2d%2d\n",$1,($2-1),$3}' | sed 's/ /0/g'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find the date of previous day in shell script?

Hi Experts, i am using the below code get the date of previous day. #!/usr/bin/ksh datestamp=`date '+%Y%m%d'` yest=$((datestamp -1)) echo $yest When i execute the code i am getting output as: 20130715 What i am trying here is, based on the date passed i am fetching previus day's... (0 Replies)
Discussion started by: learner24
0 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Previous Year Date

Hi Gurus, I would like to get the date for the previous year based on the date I specify. For e.g. If I input today's date (i.e. 20130422) I need to get 20120422. We don't have GNU and use K Shell. Any help is highly appreciated. Thanks Shash (4 Replies)
Discussion started by: shash
4 Replies

3. Shell Programming and Scripting

Can i get the previous/next days date of a selected day

Ok, the title is confusing i know, but it is a weird question. I have a bash script running on Centos5.8 and want to find a better way to do some date manipulation. What i am trying to do is get 3 days of files (day before, that day, and day after), concatenate the three files and pass them on... (2 Replies)
Discussion started by: oly_r
2 Replies

4. UNIX for Dummies Questions & Answers

[SOLVED] how to extract the day and month from a user supplied date ?

Hi All , I am trying to extract the day and month from a user supplied date . But not able . Please help . This is what I am trying to do , I have followed other articles in this scenario. userdate=$1 echo "Script parameter userdate is $userdate" The output of this is in this... (7 Replies)
Discussion started by: megha2525
7 Replies

5. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

6. Shell Programming and Scripting

Script to check if last modified day is previous day

Hi, I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it. For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Discussion started by: hegdepras
1 Replies

7. Shell Programming and Scripting

finding the previous day date and creating a file with date

Hi guys, I had a scenario... 1. I had to get the previous days date in yyyymmdd format 2. i had to create a file with Date inthe format yyyymmdd.txt format both are different thanks guys in advance.. (4 Replies)
Discussion started by: apple2685
4 Replies

8. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

9. Shell Programming and Scripting

needs to display month for previous day date

Hello, I wanted to display the month for previous day date. Like, today date is 18-Nov-2008. So the previous date is 17-Nov-2008. The output should be November. If the today date is 1-DEC-2008, then output should be NOVEMBER. If the today date is 1-JAN-2008, then output should be DECEMBER.... (4 Replies)
Discussion started by: govindts
4 Replies

10. Shell Programming and Scripting

Previous day's date in Perl?

Hi All, I want to find the previous day's date and store that in a variable, which will be usuful for further processing. Any help please. Regards, raju (4 Replies)
Discussion started by: rajus19
4 Replies
Login or Register to Ask a Question