Display the last five dates from the given date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display the last five dates from the given date
# 1  
Old 07-10-2009
Display the last five dates from the given date

Hi all,

In Oracle we have got sysdate -1 to find the previous date. Is there any similar way to display date in unix shell scripting?

Kindly help me to display the last five dates from the given date

Thanks,
Geetha
# 2  
Old 07-10-2009
# 3  
Old 07-10-2009
Code:
#!/bin/ksh93

for i in {1..5}
do
     printf "%(%D)T\n" "$i day ago"
done

Code:
07/09/09
07/08/09
07/07/09
07/06/09
07/05/09

# 4  
Old 07-10-2009
Here's a little function I created. May not work on all linux systems. Thanks.

Code:
function days_ago {
  DAYAGO=$1
  set -- $(date -d "$DAYAGO days ago" "+%Y %m %d")
  YYYY=$1 ; MM=$2 ; DD=$3
  CHECKDATE=${YYYY}${MM}${DD}
  shift $#
}

# 5  
Old 07-10-2009
Code:
DATE=$(date '+%s')  # now
for I in 0 1 2 3 4; do
  perl -e "print scalar(localtime($DATE)). \"\n\""
  let DATE=$DATE-86400 # 1 day ago
done
 
Fri Jul 10 17:56:11 2009
Thu Jul  9 17:56:11 2009
Wed Jul  8 17:56:11 2009
Tue Jul  7 17:56:11 2009
Mon Jul  6 17:56:11 2009

# 6  
Old 09-20-2009
Hi
Please help on to display the dates if 1st of month is sunday,from sunday(Current month) to thursday of previous month.If its monday ,from monday to thursday of previous month

ex:
1st of month:01-03-2009(Sunday)
28-02-2009
27-02-2009
26-02-2009(thursday)

Thanks,
MR
# 7  
Old 09-21-2009
with GNU date:

application GNUdate GNU date

you can use it to show the date as you expect:

Code:
for i in {1..5}
do
  gdate -d "$i days ago"
done


Last edited by rdcwayx; 09-21-2009 at 04:10 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display dates between two dates

Hi All, I have 2 dates in mm/dd format. sdate=10/01 (October 01) edate=10/10 (October 10) I need the dates in between these 2 dates like below. 10/01 10/02 10/03 10/04 10/05 10/06 10/07 10/08 (1 Reply)
Discussion started by: jayadanabalan
1 Replies

2. Shell Programming and Scripting

Display previous days dates in ksh

---------- Post updated at 03:42 AM ---------- Previous update was at 03:38 AM ---------- Sorry for a duplicate post, my post at the first place could not appear due to some net issue on my machine. Here is what i posted earlier: Hi, i am using ksh in Solaris, i wanted to assign today's,... (5 Replies)
Discussion started by: pr5439
5 Replies

3. Shell Programming and Scripting

Display data from a range of dates

I have a data in a file called SCHED which has 5 columns: sched no, date, time, place and remarks. The image is shown below. http://dl.dropbox.com/u/54949888/Screenshot%20from%202013-01-02%2002%3A42%3A25.png Now, I want to display only the schedules which fall under a certain date range which... (2 Replies)
Discussion started by: angilulu
2 Replies

4. Shell Programming and Scripting

ksh compare dates INSIDE a file (ie date A is > date B)

In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line. I thought I would... (4 Replies)
Discussion started by: right_coaster
4 Replies

5. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

6. Shell Programming and Scripting

Need to capture all dates between start date and End date.

Hi All, I enter Start date and end date as parameters. I need to capture dates between start date and end date. Please let me know if you have any idea the same. Thanks in advance. Nagaraja Akkivalli. (5 Replies)
Discussion started by: Nagaraja Akkiva
5 Replies

7. Shell Programming and Scripting

Generate quarter dates with begin date and end date

Hi All, I am trying to generate quarter dates with user giving input as begin date and end date. Example: Input by user: begin_date = "2009-01-01" end_date = 2010-04-30" required output: 2009-01-01 2009-03-31 09Q01 2009-04-01 2009-06-30 09Q02 . . till 2010-01-01 2010-03-31 10Q01 ... (9 Replies)
Discussion started by: sol_nov
9 Replies

8. Shell Programming and Scripting

display all dates 200 days back

i need help! can someone help me please? i try to calculate date under unix (ksh)...AIX operating system. I have to find the date 200 days from today's date. then the script should loop 200 times and display on command line every day's date until the current date. example: todays date:... (4 Replies)
Discussion started by: pavan_test
4 Replies

9. UNIX for Dummies Questions & Answers

display all dates 200 days back

i need help! can someone help me please? i try to calculate date under unix (ksh)...AIX operating system. I have to find the date 200 days from today's date. then the script should loop 200 times and display on command line every day's date until the current date. example: todays date:... (1 Reply)
Discussion started by: pavan_test
1 Replies

10. UNIX for Dummies Questions & Answers

Display dates within a given date range

Hi All, I have a requirement to display all the dates within the provided (through user input) date range. For eg: If I enter 28012009 (as From date in the format 'DDMMYYYY') and 02022009(as To date in the format 'DDMMYYYY'), the output should be all dates occuring between the from and to... (11 Replies)
Discussion started by: sunpraveen
11 Replies
Login or Register to Ask a Question