Hi,
Can you tell me if Date:Calc is the best way for calcuating dates? �I would like to
pass specific dates to analog to do log file analysis on the dates. �
Here are my scripts:
1)Previous Month
#!/usr/bin/perl
use Date::Calc qw( Today Days_in_Month Date_to_Text);
�($year,$month) = Today();
#calculating previous month
�if ($month == 1)
�{
� � � �$previous_mon = "12";
� � � �$year = $year - 1;
� � � �$days=Days_in_Month($year,$previous_mon);
� � � �$begin_date = "01";
� � � �$end_date = $days;
�print "Previous Month's Dates were From $year $previous_mon$begin_date To $year
$previous_mon$end_date.\n"
�}
�else
�{
� � �if ($month > 1)
� � �{
� � � � �$previous_mon = $month - 1;
� � � � �$days=Days_in_Month($year,$previous_mon);
� � � � �$begin_date = "01";
� � � � �$end_date = $days;
�print "Previous Month's Dates were From $year $previous_mon$begin_date To $year
$previous_mon$end_date.\n"
� � �}
� } �
2)Previous Week
#!/usr/bin/perl
use Date::Calc qw( Today Day_of_Week Add_Delta_Days
� � � � � � � � � � Day_of_Week_to_Text Date_to_Text );
�$saturday_dow = 6; # 6 = Saturday
�$sunday_dow = 7; # 7 = Sunday
�@today = Today();
�$current_dow = Day_of_Week(@today);
#calculating saturday's date of previous week
�if ($saturday_dow == $current_dow)
�{
� � �@prev = Add_Delta_Days(@today,-7);
�}
�else
�{
� � �if ($saturday_dow > $current_dow)
� � �{
� � � � �@next = Add_Delta_Days(@today,
� � � � � � � � � �$saturday_dow - $current_dow);
� � � � �@prev = Add_Delta_Days(@next,-7);
� � �}
� � �else
� � �{
� � � � �@prev = Add_Delta_Days(@today,
� � � � � � � � � �$saturday_dow - $current_dow);
� � � � �@next = Add_Delta_Days(@prev,+7);
� � �}
� } �
�$dow = Day_of_Week_to_Text($saturday_dow);
�print "Today is: � � �", ' ' x length($dow),
� � � � � � � � � � � � � � � Date_to_Text(@today), "\n";
@previoussaturday=@prev;
#calculating sunday's date of previous week
#sunday is 7, which is larger than any other weekday 1-7
�if ($sunday_dow == $current_dow)
�{
� � �@prev = Add_Delta_Days(@today,-14);
�}
�else
�{
� � �if ($sunday_dow > $current_dow)
� � �{
� � � � �@next = Add_Delta_Days(@today,
� � � � � � � � � �$sunday_dow - $current_dow);
� � � � �@prev = Add_Delta_Days(@next,-14);
� � �}
�}
�$dow2 = Day_of_Week_to_Text($sunday_dow);
�@previoussunday=@prev;
�print "Previous Weeks Dates were From @previoussunday To @previoussaturday.\n"
__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at
http://webmail.netscape.com/