Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #11 (permalink)  
Old April 18th, 2007, 08:34 AM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

A function called strftime is what you're after. It's in the POSIX and Date::Format CPAN modules

--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
Reply With Quote
  #12 (permalink)  
Old April 25th, 2007, 06:23 PM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I want to compare the date which i get read from the xml file with today's date and if it is greater than 60 days then need to do a action else other action.

Please share ur views with me,

Thanks in advance

Reply With Quote
  #13 (permalink)  
Old June 7th, 2007, 04:57 AM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This below prog is to calculate the diff of days.
I hardcoded most. if you want to use dd-mm-yy format you can use split function for date arrays.

#!/usr/bin/perl
                    # perl binary

@std_date=(1,1,1800); # cal starts from this year

@date_one=(21,06,2006); # first date
@date_two=(20,06,2007); # second date

@days_of_month=(31,28,31,30,31,30,31,31,30,31,30,3 1);

$count1=no_day(@std_date,@date_one); # date_one - std_date
$count2=no_day(@std_date,@date_two); # date_two - std_date
$count=($count1 > $count2) ? $count1 - $count2 : $count2 - $count1;
                    # date1 - date2

print "\n\tNo of days : $count\n\n";

sub no_day
    {
    @std=($_[0],$_[1],$_[2]);
    @date=($_[3],$_[4],$_[5]);
    $count=0;

    #adding the days for year
    for($i=$std[2];$i<$date[2];$i++)
        {
        $count+=365 if(leapyear($i));
        $count+=366 if(!(leapyear($i)));
        }

    #adding the days for month
    for($i=@std[1];$i<$date[1];$i++)
        {
        $count+=$days_of_month[$i-1];
        }

    #adding the days and return
    return($count+=$date[0]);

    }

sub leapyear # is it leap year
    {
    $in=$_[0];
    if(!($in%4))
        {
        if($in%100)
            {
            return(0); # if leap year
            }
        else
            {
            if(!($in%400))
                {
                return(0);
                }
            return(1)
            }
        }
    return(1); # if it is not leap year
    }


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between 2 dates comicghozt Access 5 July 14th, 2006 03:45 AM
Urgent! how to calculate difference between dates Subuana Beginning VB 6 2 March 22nd, 2006 04:34 PM
Difference in Dates mcinar Javascript How-To 0 May 8th, 2005 07:08 PM
Difference between two dates in Vb.net bimal VS.NET 2002/2003 5 August 15th, 2004 11:32 PM
how to calculate difference in dates ashu_gupta75 Excel VBA 3 August 9th, 2004 06:11 AM



All times are GMT -4. The time now is 08:08 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.