Sponsored Content
Top Forums Shell Programming and Scripting Perl : unable to frame code with Business:Hours module with example Post 302822697 by rajamadhavan on Tuesday 18th of June 2013 05:13:11 AM
Old 06-18-2013
Code:
#!/usr/bin/perl -w
    
use strict;
use Date::Parse;
my $datetime1="2007-12-31 16:50:00";
my $datetime2="2008-1-1 04:24:00";

my $epoch1 = str2time($datetime1);
my $epoch2 = str2time($datetime2);
#print "$epoch1, $epoch2\n";

use Business::Hours;
my $hours = Business::Hours->new();    

my %hours = (
      0 => { Name     => 'Sunday',
             Start    => '08:00',
             End      => '18:00' },

      1 => { Name     => 'Monday',
             Start    => '08:00',
             End      => '18:00' },
      
      2 => { Name     => 'Tuesday',
             Start    => '08:00',
             End      => '18:00' },

      3 => { Name     => 'Wednesday',
             Start    => '08:00',
             End      => '18:00' },

      4 => { Name     => 'Thursday',
             Start    => '08:00',
             End      => '18:00' },
      
      5 => { Name     => 'Friday',
             Start    => '08:00',
             End      => '18:00' },

      6 => { Name     => 'Saturday',
             Start    => '08:00',
             End      => '18:00' },
      ,
  );  

my $diffsec = $hours->between($epoch1,$epoch2);
my $diffmin = $diffsec/60;

printf("Diff is %2.2f min\n", $diffmin);

Code:
$ ./test.pl 
Diff is 70.00 min

This User Gave Thanks to rajamadhavan For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace Perl Module name in all Perl scripts

I want to replace a Perl module name in all my Perl Scripts in the cgi-bin directory. How is it possible? I have the following statement in my scripts use myUtil; I want to change it to use myUtil777; Regards, Rahul (2 Replies)
Discussion started by: rahulrathod
2 Replies

2. Solaris

Unable to load module

Hey guys i got this error in my messages: warning : mod_load: cannot load module sbd - I dont know anything about this. - How do i verify if there is a module sbd - What are the reasons modules cant be loaded (1 Reply)
Discussion started by: sbn
1 Replies

3. Solaris

unable to detect new cpu/memory module

Hi all, I just add in new cpu/memory module into SFV480 and unable to see new module on slot B. I already try many way like only 1 new module and swap the both module and boot up but still unable to see it. If I only install the module into slot B, then the server is unbootable at all. I... (1 Reply)
Discussion started by: mailbox80
1 Replies

4. OS X (Apple)

Unable to install Perl module via CPAN

Hi, I am trying to install Unicode::String from the cpan shell, and here is what I get: Checking if your kit is complete... Looks good Writing Makefile for Unicode::String cp String.pm blib/lib/Unicode/String.pm cp lib/Unicode/CharName.pm blib/lib/Unicode/CharName.pm... (3 Replies)
Discussion started by: psychomachine
3 Replies

5. Shell Programming and Scripting

calling perl subroutine from perl expect module

All, Is it possible to call a subroutine from the perl expect module after logging to a system that is within the same program. My situation is I need to run a logic inside a machine that I'm logging in using the expect module, the logic is also available in the same expect program. Thanks,... (5 Replies)
Discussion started by: arun_maffy
5 Replies

6. Shell Programming and Scripting

Unable to Install "Devel-Profile" perl module in windows.

Hi, I want to install 'Devel-Profile' in windows but i am not able to install. Here is the error. PPM> install Devel-Profile Install package 'Devel-Profile?' (y/N): y Installing package 'Devel-Profile'... Error installing package 'Devel-Profile': Could not locate a PPD file for... (3 Replies)
Discussion started by: vanitham
3 Replies

7. Infrastructure Monitoring

Nagios - alert during business hours

Is there a way for certain nagios alerts to only alert during business hours? (1 Reply)
Discussion started by: streetfighter2
1 Replies

8. Shell Programming and Scripting

Unable to install module using cpan

Hi, I am unable to install module using cpan. It says 407 Proxy Authentication Required I did setup proxy server and given username and password in .bashrc file and apt.conf file. export http_proxy=http://username:password@proxyserver:portno/ However, still unable to install... (1 Reply)
Discussion started by: Anjan1
1 Replies

9. Shell Programming and Scripting

awk : Search for text between two time frame (12 hours)

I have created the script to grep the errors from weblogic logs files and redirecting output to file.txt ...From file.txt I'm using awk command to collect the past 20 mins output...The script running from cron every 15 mins... The script working well... Now the challenges, I'm trying to use... (27 Replies)
Discussion started by: zenkarthi
27 Replies

10. Shell Programming and Scripting

CGI Perl : only frame is getting updated

I am working on CGI perl and trying to overcome the below problem.. I have divided the page into 3 frames( attached the screenshot) how to my frameset look like. In frame2, there will be a cgi script consisting on names(links), when clicked on link , the frame3 should get changed. But in... (1 Reply)
Discussion started by: scriptscript
1 Replies
DATETIME.DIFF(3)							 1							  DATETIME.DIFF(3)

DateTime::diff - Returns the difference between two DateTime objects

       Object oriented style

SYNOPSIS
public DateInterval DateTime::diff (DateTimeInterface $datetime2, [bool $absolute = false]) DESCRIPTION
DateInterval DateTimeImmutable::diff (DateTimeInterface $datetime2, [bool $absolute = false]) DateInterval DateTimeInterface::diff (Date- TimeInterface $datetime2, [bool $absolute = false]) Procedural style DateInterval date_diff (DateTimeInterface $datetime1, DateTimeInterface $datetime2, [bool $absolute = false]) Returns the difference between two DateTimeInterface objects. PARAMETERS
o $datetime - The date to compare to. o $absolute - Should the interval be forced to be positive? RETURN VALUES
The DateInterval object representing the difference between the two dates or FALSE on failure. EXAMPLES
Example #1 DateTime.diff(3) example Object oriented style <?php $datetime1 = new DateTime('2009-10-11'); $datetime2 = new DateTime('2009-10-13'); $interval = $datetime1->diff($datetime2); echo $interval->format('%R%a days'); ?> Procedural style <?php $datetime1 = date_create('2009-10-11'); $datetime2 = date_create('2009-10-13'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%R%a days'); ?> The above examples will output: +2 days Example #2 DateTime object comparison Note As of PHP 5.2.2, DateTime objects can be compared using comparison operators. <?php $date1 = new DateTime("now"); $date2 = new DateTime("tomorrow"); var_dump($date1 == $date2); var_dump($date1 < $date2); var_dump($date1 > $date2); ?> The above example will output: bool(false) bool(true) bool(false) SEE ALSO
DateInterval.format(3), DateTime.add(3), DateTime.sub(3). PHP Documentation Group DATETIME.DIFF(3)
All times are GMT -4. The time now is 05:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy