[EMAIL PROTECTED] wrote:
> From: sekhar kavuru [mailto:[EMAIL PROTECTED]
>> 
>> I need help with a generic function that can give the value of next
>> day Example : 12/31/2005 => 01/01/2006
>> 
>> I want to accomplish this without Cal::Date

Fine, but by using timelocal and localtime together, you can generate the point 
in time and then  add 1 day ( 86400 ) to the point in time to get the next day. 
By doing that, it becomes one use statement plus 3 more lines give or take to 
get you the next day. You don't have to go through all the other checks. 

Wags ;)
> 
> Are you saying you want to do it without using a date module, or
> without using that particular date module?
> 
> Let me give it a quick shot (off-the-cuff and completely untested):
> 
> ------------------------------------------------
> sub nextDay
> {
>     $date = shift;
> 
>     @month_days = ( undef, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
> 30, 31 ); 
> 
>     ($m, $d, $y) = $date =~ m#(\d+)/(\d+)/(\d+)#;
> 
>     # Check for leap year
>     if ($y % 4 == 0)
>     {
>         $month_days[2]++;
>     }
> 
>     $d++;
> 
>     if ($d > $month_days[$m])
>     {
>         $d = 1;
>         $m++;
>     }
> 
>     if ($m > 12)
>     {
>         $m = 1;
>         $y++;
>     }
> 
>     return "$m/$d/$y";
> }
> ------------------------------------------------
> 
> Caveats:
> - This assumes the incoming date is valid
> - There needs to be a few more checks for the leap year, but I'm too
>   lazy to look it up right now.
> 
> Bowie
> _______________________________________________
> ActivePerl mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
  • RE: Perl code to get n... Wagner, David --- Senior Programmer Analyst --- WGO

Reply via email to