processing for each day given a date range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting processing for each day given a date range
# 1  
Old 03-09-2010
processing for each day given a date range

hello,

I have a date range submitted by the user in ddmmyy format. how can i do some processing for each day. E.g. date params are 020110 (start date 01 jan 10) and 300110 (30 jan 10),

i.e
for each day in the date range
do some processing...
until end date has been reached.

thanks!
# 2  
Old 03-09-2010
Check the man page for the date command, and let us know if it supports date arithmetic. Or let us know the OS and release.
# 3  
Old 03-09-2010
what is your version of date ?
Do you have the -d option ?
# 4  
Old 03-09-2010
Quote:
Originally Posted by Wahmed9
...how can i do some processing for each day. E.g. date params are 020110 (start date 01 jan 10) and 300110 (30 jan 10),

i.e
for each day in the date range
do some processing...
until end date has been reached.

...
If you have Perl installed in your OS, then you could do something like this:

Code:
$ 
$ 
$ cat -n iterate.pl
     1  #!/usr/bin/perl -w
     2  use Date::Calc qw( Delta_Days Add_Delta_Days );
     3  @start = reverse unpack("A2A2A4",$ARGV[0]);
     4  @stop  = reverse unpack("A2A2A4",$ARGV[1]);
     5  for ( $i = 0; $i <= Delta_Days(@start,@stop); $i++ ) {
     6    printf("Now processing : %4d/%02d/%02d\n", Add_Delta_Days(@start,$i));
     7  }
$ 
$ ./iterate.pl 01012010 30012010
Now processing : 2010/01/01
Now processing : 2010/01/02
Now processing : 2010/01/03
Now processing : 2010/01/04
Now processing : 2010/01/05
Now processing : 2010/01/06
Now processing : 2010/01/07
Now processing : 2010/01/08
Now processing : 2010/01/09
Now processing : 2010/01/10
Now processing : 2010/01/11
Now processing : 2010/01/12
Now processing : 2010/01/13
Now processing : 2010/01/14
Now processing : 2010/01/15
Now processing : 2010/01/16
Now processing : 2010/01/17
Now processing : 2010/01/18
Now processing : 2010/01/19
Now processing : 2010/01/20
Now processing : 2010/01/21
Now processing : 2010/01/22
Now processing : 2010/01/23
Now processing : 2010/01/24
Now processing : 2010/01/25
Now processing : 2010/01/26
Now processing : 2010/01/27
Now processing : 2010/01/28
Now processing : 2010/01/29
Now processing : 2010/01/30
$ 
$

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace date in file every day with current date

I Have text like XXX_20190908.csv.gz need to replace Only date in this format with current date every day Thanks! (1 Reply)
Discussion started by: yamasani1991
1 Replies

2. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

3. AIX

Need to get the next day's date of the user entered date

I need to get the next day's date of the user entered date for example: Enter date (yyyy/mm/yy): 2013/10/08I need to get the next day's date of the user entered date Desired Output: 2013/10/09Though there are ways to achieve this is Linux or Unix environment (date command) ,I need to... (1 Reply)
Discussion started by: rpm120
1 Replies

4. Shell Programming and Scripting

Date listing in a date range

Solaris 10 ksh88 Sorry for re-hashing some of this, but I can't find a proper solution in the forums. Starting with /a/archive containing (on and on date formatted directories) 20060313 20080518 20100725 20121015 20060314 20080519 ... (1 Reply)
Discussion started by: moesplace
1 Replies

5. 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

6. UNIX for Dummies Questions & Answers

Getting date -1 day not using GNU date

It's easy as pie to get the date minus one day on opensolaris: date -d "-1 day" +"%Y%m%d"run this command on our crappy Solaris 10 machines however (which I'm guessing doesn't have GNU date running on it) and you get: date: illegal option -- d date: illegal option -- 1 date: illegal option --... (5 Replies)
Discussion started by: rich@ardz
5 Replies

7. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

8. UNIX Desktop Questions & Answers

date range

I have a number of instances wher I need to run reports for the previous month and need to include the last months date range in the sql. I want to create a string which consists of the first and last dates of last month separated with an ' and ' ie for this month (Feb) I want it to say '01/01/10... (3 Replies)
Discussion started by: Niven
3 Replies

9. Shell Programming and Scripting

Day '29' out of range 1..28 at

Hi all, I wrote few lines of code to check how long a process has been uptime. I work on Solaris SunOS 5.10 and perl v5.8.4. Here is the code: #!/usr/bin/perl use Time::Local; $service="TCPIPSCH"; $PID_SERVICE=`ps -ef | grep -w $service | grep -v grep | awk '{print \$2}'`; if... (2 Replies)
Discussion started by: Evan
2 Replies

10. Shell Programming and Scripting

Get date range between 2 date input

Hi Experts, I have files name report_20090416 report_20090417 report_20090418 report_20090420 report_20090421 I have 2 input from user From Date: 20090417 To Date: 20090420 and I need to grep only those line in between. Output should be report_20090417 report_20090418... (3 Replies)
Discussion started by: tanit
3 Replies
Login or Register to Ask a Question