954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need Help in Calculating a DateRange

Good Day to All:

I need to know if there is a code snippet somewher that will allow me to take a users START DATE and give them a maximum of seven(7) for a END DATE.

Problem is, on my AIX box, we DO NOT HAVE THE Date::Calc Perl Module.

Is there a simple way to calculate this date range.....?????

PLEASE HELP....!!!!!!!:eek:

kxh29
Junior Poster in Training
56 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

Why don't you search in CPAN??

if you really need Date::Calc module you can get that too from CPAN, here is the link http://search.cpan.org/~stbey/Date-Calc-5.4/Calc.pod

download it and try you need.

kath.

katharnakh
Posting Whiz in Training
237 posts since Jan 2006
Reputation Points: 19
Solved Threads: 34
 

whats the format of the start date?

KevinADC
Posting Shark
921 posts since Mar 2006
Reputation Points: 246
Solved Threads: 67
 
whats the format of the start date?



Good Morning Kath:

Unfortunately, I come from "BIG_IT_FARM":mad: , but the company I am at now, is a small IOT shop and I just luv'it:mrgreen:

Unfortunately, because of their size, and the distribution of the UNIX admin guys, I do not have the "authorization" at this time to load up modules from CPAN.:-|

So.......I am working on a solution with another one of our members. I will let you know the results.

Thanks much,

Kevin:

kxh29
Junior Poster in Training
56 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 
whats the format of the start date?



Good Morning Kevin:

The format is as follows:

Start Date:==> 08/01/07
End Date:==> 08/08/07

Basically, give them a range <= seven(7) days. If they exceed this, then, bells, whistles.....abort, retry.........ei-ei-o.

Funny enough, I had actually written this logic years ago, and I am sure I could do it again, .....but my hair is on fire constatnly......!!!

Please let me know. Thanks Kevin!

Kevin:

kxh29
Junior Poster in Training
56 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 
use Time::Local 'timelocal_nocheck';
use POSIX 'strftime';
my $s_date = '08/01/07';
my $e_date = get_edate($s_date);
print "start date:$s_date, end date: $e_date";
sub get_edate {
   my $s_date = shift || return(0);
   my ($m,$md,$y) = $s_date =~ m|(\d+)/(\d+)/(\d+)|;
   my $epochtime = timelocal_nocheck(0, 0, 0, $md, $m-1, $y);
   return strftime("%m/%d/%y",0,0,0,(localtime($epochtime+604800))[3,4,5]);
}
KevinADC
Posting Shark
921 posts since Mar 2006
Reputation Points: 246
Solved Threads: 67
 
use Time::Local 'timelocal_nocheck';
use POSIX 'strftime';
my $s_date = '08/01/07';
my $e_date = get_edate($s_date);
print "start date:$s_date, end date: $e_date";
sub get_edate {
   my $s_date = shift || return(0);
   my ($m,$md,$y) = $s_date =~ m|(\d+)/(\d+)/(\d+)|;
   my $epochtime = timelocal_nocheck(0, 0, 0, $md, $m-1, $y);
   return strftime("%m/%d/%y",0,0,0,(localtime($epochtime+604800))[3,4,5]);
}



Kevin:

Thanks for the solution! I have not had a chance to walk thru it in detail. I need to understand the strftime function call and what is going on:eek: ! Can you give a short descritption...???? If not, I greatly appreciate your assistance. Please let me know

kxh29
Junior Poster in Training
56 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

google for:

posix strftime function

you will find plenty of resources that explain the strftime function in detail and POSIX in general.

KevinADC
Posting Shark
921 posts since Mar 2006
Reputation Points: 246
Solved Threads: 67
 
google for: posix strftime function you will find plenty of resources that explain the strftime function in detail and POSIX in general.



Kevin:

Thanks Much for your assistance! I will check that site asap.

Kevin:

kxh29
Junior Poster in Training
56 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You