Re: [SLUG] subracting dates from dates

2001-12-17 Thread Broun, Bevan

on Tue, Dec 18, 2001 at 11:47:57AM +1100, George Vieira 
[EMAIL PROTECTED] wrote:
 Hi all,
 
 Is there a way to subtract the number of days remaining from a date so I can
 report back 125 days remaining etc.. under linux/perl?
 
 I want to subtract it from a date which will be a special event etc..
 Is there a date to interger conversion or something?

This can be done using the C routines that are found in time.h. I found a
very useful shell impleamentation of the C routines called mktime, you may
have trouble finding this. This gives you a mktime command that you can run
and you can do excactly what you want. 

BB

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug



Re: [SLUG] subracting dates from dates

2001-12-17 Thread Tony Green

* This one time, at band camp, George Vieira said:
 Hi all,
 
 Is there a way to subtract the number of days remaining from a date so I can
 report back 125 days remaining etc.. under linux/perl?
 
 I want to subtract it from a date which will be a special event etc..
 Is there a date to interger conversion or something?
 

If your dates are in Epoch seconds, and fall in the range Fri Dec 13 20:45:52 1901 to 
Tue Jan 19 03:14:07 2038 (inclusive), simply subtract one from the other and convert 
the seconds to days.

$seconds = $recent - $earlier;

If you have distinct DMYMHS values, or are worried about the range limitations of 
Epoch seconds, use the Date::Calc module from CPAN. It can calculate the difference 
between dates:

use Date::Calc qw(Delta_Days);
$days = Delta_Days( $year1, $month1, $day1, $year2, $month2, $day2);

It also calculates the difference between dates and times:

use Date::Calc qw(Delta_DHMS);
($days, $hours, $minutes, $seconds) =
  Delta_DHMS( $year1, $month1, $day1, $hour1, $minute1, $seconds1,  # earlier
  $year2, $month2, $day2, $hour2, $minute2, $seconds2); # later

Discussion

One problem with Epoch seconds is how to convert the large integers back to forms that 
people can read. The following example shows one way of converting an Epoch seconds 
value back to its component numbers of weeks, days, hours, minutes, and seconds:

$bree = 361535725;  # 16 Jun 1981, 4:35:25
$nat  =  96201950;  # 18 Jan 1973, 3:45:50

$difference = $bree - $nat;
print There were $difference seconds between Nat and Bree\n;
There were 265333775 seconds between Nat and Bree

$seconds=  $difference % 60;
$difference = ($difference - $seconds) / 60;
$minutes=  $difference % 60;
$difference = ($difference - $minutes) / 60;
$hours  =  $difference % 24;
$difference = ($difference - $hours)   / 24;
$days   =  $difference % 7;
$weeks  = ($difference - $days)/  7;

print ($weeks weeks, $days days, $hours:$minutes:$seconds)\n;
(438 weeks, 4 days, 23:49:35)

Date::Calc's functions can ease these calculations. The Delta_Days function returns 
the number of days between two dates. It takes the two dates as a list: year, month, 
day. The dates are given chronologically  - earliest first.

use Date::Calc qw(Delta_Days);
@bree = (1981, 6, 16);  # 16 Jun 1981
@nat  = (1973, 1, 18);  # 18 Jan 1973
$difference = Delta_Days(@nat, @bree);
print There were $difference days between Nat and Bree\n;
There were 3071 days between Nat and Bree

The Delta_DHMS function returns a four-element list corresponding to the number of 
days, hours, minutes, and seconds between the two dates you give it.

use Date::Calc qw(Delta_DHMS);
@bree = (1981, 6, 16, 4, 35, 25);   # 16 Jun 1981, 4:35:25
@nat  = (1973, 1, 18, 3, 45, 50);   # 18 Jan 1973, 3:45:50
@diff = Delta_DHMS(@nat, @bree);
print Bree came $diff[0] days, $diff[1]:$diff[2]:$diff[3] after Nat\n;
Bree came 3071 days, 0:49:35 after Nat

See Also

The documentation for the CPAN module Date::Calc
-- 
Greeno [EMAIL PROTECTED]
GnuPG Key :  1024D/B5657C8B 
Key fingerprint = 9ED8 59CC C161 B857 462E  51E6 7DFB 465B B565 7C8B

Imagine working in a secure environment and finding the string 
_NSAKEY in the OS binaries without a good explanation
-Alan Cox 04/05/2001

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug



Re: [SLUG] subracting dates from dates

2001-12-17 Thread cpaul


On Tue, 18 Dec 2001 11:47:57 +1100 George Vieira wrote:

 Is there a way to subtract the number of days remaining from a date so I can
 report back 125 days remaining etc.. under linux/perl?

you may also find Class::Date useful.

ftp://mirror.aarnet.edu.au/pub/perl/CPAN/authors/id/D/DL/DLUX/Class-Date-1.0.8.tar.gz


-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug



RE: [SLUG] subracting dates from dates

2001-12-17 Thread George Vieira

Thanks to all that replied..

I found a way to do it in bash but now want to use perl to check the passed
in date for it's format ie... mm/dd/ format.

I'd be happy with just 00-99 numbers..

At the moment I've done this (below) in shell commands in perl but wanted to
pass in $date is possible and checked too for errors.. I've taken a big
guess and tried it.. it seems to work (OMG) but would like suggestions...

# This part was original test and works but want $in{eventdate} to replace
$date
$date=02/23/2002;
$event=`date -d \$date +%s`;
$nowdate=`date +%s`;
$daysleft=`echo $((($event - $nowdate) / 86400 ))`;
if ( $in{eventdate} !~ /^[0-9]+[\/]+[0-9]+[\/]+[-]+$/ ){
print EOT;
Content-type: text/plain
Invalid Date Format with $in{eventdate}
EOT
exit(0);
}
else
{ print $in{eventdate} is just fine;


any help with this I appreciate it.

thanks,
George Vieira
Systems Manager
Citadel Computer Systems P/L


-Original Message-
From: Tony Green [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 18 December 2001 12:00 PM
To: Sydney Linux Users Group (E-mail)
Subject: Re: [SLUG] subracting dates from dates


* This one time, at band camp, George Vieira said:
 Hi all,
 
 Is there a way to subtract the number of days remaining from a date so I
can
 report back 125 days remaining etc.. under linux/perl?
 
 I want to subtract it from a date which will be a special event etc..
 Is there a date to interger conversion or something?
 

If your dates are in Epoch seconds, and fall in the range Fri Dec 13
20:45:52 1901 to Tue Jan 19 03:14:07 2038 (inclusive), simply subtract one
from the other and convert the seconds to days.

$seconds = $recent - $earlier;

If you have distinct DMYMHS values, or are worried about the range
limitations of Epoch seconds, use the Date::Calc module from CPAN. It can
calculate the difference between dates:

use Date::Calc qw(Delta_Days);
$days = Delta_Days( $year1, $month1, $day1, $year2, $month2, $day2);

It also calculates the difference between dates and times:

use Date::Calc qw(Delta_DHMS);
($days, $hours, $minutes, $seconds) =
  Delta_DHMS( $year1, $month1, $day1, $hour1, $minute1, $seconds1,  #
earlier
  $year2, $month2, $day2, $hour2, $minute2, $seconds2); # later

Discussion

One problem with Epoch seconds is how to convert the large integers back to
forms that people can read. The following example shows one way of
converting an Epoch seconds value back to its component numbers of weeks,
days, hours, minutes, and seconds:

$bree = 361535725;  # 16 Jun 1981, 4:35:25
$nat  =  96201950;  # 18 Jan 1973, 3:45:50

$difference = $bree - $nat;
print There were $difference seconds between Nat and Bree\n;
There were 265333775 seconds between Nat and Bree

$seconds=  $difference % 60;
$difference = ($difference - $seconds) / 60;
$minutes=  $difference % 60;
$difference = ($difference - $minutes) / 60;
$hours  =  $difference % 24;
$difference = ($difference - $hours)   / 24;
$days   =  $difference % 7;
$weeks  = ($difference - $days)/  7;

print ($weeks weeks, $days days, $hours:$minutes:$seconds)\n;
(438 weeks, 4 days, 23:49:35)

Date::Calc's functions can ease these calculations. The Delta_Days function
returns the number of days between two dates. It takes the two dates as a
list: year, month, day. The dates are given chronologically  - earliest
first.

use Date::Calc qw(Delta_Days);
@bree = (1981, 6, 16);  # 16 Jun 1981
@nat  = (1973, 1, 18);  # 18 Jan 1973
$difference = Delta_Days(@nat, @bree);
print There were $difference days between Nat and Bree\n;
There were 3071 days between Nat and Bree

The Delta_DHMS function returns a four-element list corresponding to the
number of days, hours, minutes, and seconds between the two dates you give
it.

use Date::Calc qw(Delta_DHMS);
@bree = (1981, 6, 16, 4, 35, 25);   # 16 Jun 1981, 4:35:25
@nat  = (1973, 1, 18, 3, 45, 50);   # 18 Jan 1973, 3:45:50
@diff = Delta_DHMS(@nat, @bree);
print Bree came $diff[0] days, $diff[1]:$diff[2]:$diff[3] after Nat\n;
Bree came 3071 days, 0:49:35 after Nat

See Also

The documentation for the CPAN module Date::Calc
-- 
Greeno [EMAIL PROTECTED]
GnuPG Key :  1024D/B5657C8B 
Key fingerprint = 9ED8 59CC C161 B857 462E  51E6 7DFB 465B B565 7C8B

Imagine working in a secure environment and finding the string 
_NSAKEY in the OS binaries without a good explanation
-Alan Cox 04/05/2001

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug



RE: [SLUG] subracting dates from dates

2001-12-17 Thread George Vieira

OK.. I figure some things out and this is really messy I know but at least
it works for me...

print Content-type: text/plain\n\n;

if ( $in{eventdate} !~ /^[0-9]+[\/]+[0-9]+[\/]+[0-9]+[0-9]+[0-9]+[0-9]$/
){
  print TBA;
  exit(0);
}
else
{
  $date=$in{eventdate};
  $event=`date -d \$date\ +\%s\`;
  $nowdate=`date +%s`;
  $daysleft=int (eval ((( $event - $nowdate ) / 86400 )));
  print $daysleft;
}

Thanks for all your help.. will try the full perl when I get around to it..

George Vieira
Systems Manager
Citadel Computer Systems P/L


-Original Message-
From: George Vieira 
Sent: Tuesday, 18 December 2001 1:02 PM
To: Sydney Linux Users Group (E-mail)
Subject: RE: [SLUG] subracting dates from dates


Thanks to all that replied..

I found a way to do it in bash but now want to use perl to check the passed
in date for it's format ie... mm/dd/ format.

I'd be happy with just 00-99 numbers..

At the moment I've done this (below) in shell commands in perl but wanted to
pass in $date is possible and checked too for errors.. I've taken a big
guess and tried it.. it seems to work (OMG) but would like suggestions...

# This part was original test and works but want $in{eventdate} to replace
$date
$date=02/23/2002;
$event=`date -d \$date +%s`;
$nowdate=`date +%s`;
$daysleft=`echo $((($event - $nowdate) / 86400 ))`;
if ( $in{eventdate} !~ /^[0-9]+[\/]+[0-9]+[\/]+[-]+$/ ){
print EOT;
Content-type: text/plain
Invalid Date Format with $in{eventdate}
EOT
exit(0);
}
else
{ print $in{eventdate} is just fine;


any help with this I appreciate it.

thanks,
George Vieira
Systems Manager
Citadel Computer Systems P/L


-Original Message-
From: Tony Green [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 18 December 2001 12:00 PM
To: Sydney Linux Users Group (E-mail)
Subject: Re: [SLUG] subracting dates from dates


* This one time, at band camp, George Vieira said:
 Hi all,
 
 Is there a way to subtract the number of days remaining from a date so I
can
 report back 125 days remaining etc.. under linux/perl?
 
 I want to subtract it from a date which will be a special event etc..
 Is there a date to interger conversion or something?
 

If your dates are in Epoch seconds, and fall in the range Fri Dec 13
20:45:52 1901 to Tue Jan 19 03:14:07 2038 (inclusive), simply subtract one
from the other and convert the seconds to days.

$seconds = $recent - $earlier;

If you have distinct DMYMHS values, or are worried about the range
limitations of Epoch seconds, use the Date::Calc module from CPAN. It can
calculate the difference between dates:

use Date::Calc qw(Delta_Days);
$days = Delta_Days( $year1, $month1, $day1, $year2, $month2, $day2);

It also calculates the difference between dates and times:

use Date::Calc qw(Delta_DHMS);
($days, $hours, $minutes, $seconds) =
  Delta_DHMS( $year1, $month1, $day1, $hour1, $minute1, $seconds1,  #
earlier
  $year2, $month2, $day2, $hour2, $minute2, $seconds2); # later

Discussion

One problem with Epoch seconds is how to convert the large integers back to
forms that people can read. The following example shows one way of
converting an Epoch seconds value back to its component numbers of weeks,
days, hours, minutes, and seconds:

$bree = 361535725;  # 16 Jun 1981, 4:35:25
$nat  =  96201950;  # 18 Jan 1973, 3:45:50

$difference = $bree - $nat;
print There were $difference seconds between Nat and Bree\n;
There were 265333775 seconds between Nat and Bree

$seconds=  $difference % 60;
$difference = ($difference - $seconds) / 60;
$minutes=  $difference % 60;
$difference = ($difference - $minutes) / 60;
$hours  =  $difference % 24;
$difference = ($difference - $hours)   / 24;
$days   =  $difference % 7;
$weeks  = ($difference - $days)/  7;

print ($weeks weeks, $days days, $hours:$minutes:$seconds)\n;
(438 weeks, 4 days, 23:49:35)

Date::Calc's functions can ease these calculations. The Delta_Days function
returns the number of days between two dates. It takes the two dates as a
list: year, month, day. The dates are given chronologically  - earliest
first.

use Date::Calc qw(Delta_Days);
@bree = (1981, 6, 16);  # 16 Jun 1981
@nat  = (1973, 1, 18);  # 18 Jan 1973
$difference = Delta_Days(@nat, @bree);
print There were $difference days between Nat and Bree\n;
There were 3071 days between Nat and Bree

The Delta_DHMS function returns a four-element list corresponding to the
number of days, hours, minutes, and seconds between the two dates you give
it.

use Date::Calc qw(Delta_DHMS);
@bree = (1981, 6, 16, 4, 35, 25);   # 16 Jun 1981, 4:35:25
@nat  = (1973, 1, 18, 3, 45, 50);   # 18 Jan 1973, 3:45:50
@diff = Delta_DHMS(@nat, @bree);
print Bree came $diff[0] days, $diff[1]:$diff[2]:$diff[3] after Nat\n;
Bree came 3071 days, 0:49:35 after Nat

See Also

The documentation for the CPAN module Date::Calc
-- 
Greeno [EMAIL PROTECTED]
GnuPG Key :  1024D/B5657C8B 
Key fingerprint = 9ED8 59CC C161 B857 462E  51E6 7DFB 465B