Dates

2005-01-06 Thread Tim Wolak
Hello all,
I am in need of a quick way to get the current date in the MMDD 
format.  This is something I would like to understand better on how to 
get the date with perl.  Any suggestions would be most welcome.

Tim
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Dates

2005-11-04 Thread Scott Taylor

Hello,

I have a date in UT that looks like this:
"2005-11-02 01:36:00.0"

Can anyone tell me the best way to subtract 8 hours from it, or to convert
it to PDT?

I'm reading up on Date::Manip, but I don't know if that is going to help,
yet.

Cheers.

--
Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




dates

2006-10-10 Thread Tim Wolak
Just a quick easy one, while printing localtime, how do I get it to
print the full minutes and seconds, i.e. :02??

Thanks,
Tim

my $date;
my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5];
$year=$year+1900;
$mon=$mon+1;
$date = sprintf("%02d%02d%02d\_$hour\:$min\:$sec", $year,$mon,$mday);


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Dates

2003-08-19 Thread Support
Thanks to all those who replied.
I ended up doing some research myself and found a good date module at
http://search.cpan.org/author/STBEY/Date-Pcalc-1.2
for those who are interested in juggling dates. Its called Date::Pcalc
Cheers
Colin
---
www.rentmyplace.co.nz
The ultimate in that holiday spot away from the maddening crowd
Join as a member today its FREE
List your holiday accommodation for FREE


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.510 / Virus Database: 307 - Release Date: 14/08/2003

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Dates

2002-02-01 Thread Argenis Perez

this statement
($sec,$min,$hour,$mon,$year,$wday,$yday,$isdst) = localtime();
i obtain the date of today, but i need the $day,$mon,$year of yesterday

How?

Thank you

Argenis Perez
-- 
Nunca creas feliz a nadie que esté pendiente de la felicidad.
Se apoya en una base frágil quien pone su alegría en lo adventicio.
El goce que viene de afuera, afuera se irá.
Por el contrario, aquel que nace de uno mismo
es fiel y firme, y crece, y nos acompaña hasta el fin.

- Lucio Anneo Séneca -



Saludos
Argenis Perez













 






__
Your favorite stores, helpful shopping tools and great gift ideas. Experience the 
convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Dates

2005-01-06 Thread Markus Mayr
Tim Wolak wrote:
Hello all,
I am in need of a quick way to get the current date in the MMDD 
format.  This is something I would like to understand better on how to 
get the date with perl.  Any suggestions would be most welcome.

Tim
Hi.
You're probably looking for localtime?
> perldoc -f localtime
localtime will return a list with 9 elements.
> ($sec, $min, $hour, $day, $month, $year, $weekday, $dayofyear, 
$isdst) = localtime(time);

Note that you should add 1900 to $year, because $year is simply the 
actual year minus 1900 - that was fine during the 20th century, but it 
might cause errors nowadays.

Read "perldoc -f localtime".
Your program could be:
#!/usr/bin/perl
my ($sec, $min, $hour, $day, $month, $year, $weekday, $dayofyear, 
$isDST) = localtime(time);
$year += 1900;
print $year, $month, $day;

__END__
Markus Mayr
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Dates

2005-01-06 Thread Jeff Eggen
>>> Tim Wolak <[EMAIL PROTECTED]> 06/01/2005 3:59:26 pm >>>
>Hello all,

>I am in need of a quick way to get the current date in the MMDD 
>format.  This is something I would like to understand better on how to

>get the date with perl.  Any suggestions would be most welcome.

As per the perlcheat page: "just use POSIX::strftime!"

# Begin
use POSIX qw(strftime);

my $date = strftime("%Y%m%d", localtime());
# End

There's possibly something in Date::Calc as well.  But this is the
quickest way I know, especially if you're familiar with the date command
in *nix.

Hope this helps,

DISCLAIMER*
This e-mail and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed.  If 
you are not the named addressee, please notify the sender immediately by e-mail 
if you have received this e-mail by mistake and delete this e-mail from your 
system. If you are not the intended recipient you are notified that using, 
disclosing, copying or distributing the contents of this information is 
strictly prohibited.
DISCLAIMER*

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Dates

2005-01-06 Thread Owen Cook

On Thu, 6 Jan 2005, Tim Wolak wrote:

> I am in need of a quick way to get the current date in the MMDD 
> format.  This is something I would like to understand better on how to 
> get the date with perl.  Any suggestions would be most welcome.


You need to read up on localtime.

---
#!/usr/bin/perl -w

use strict;

my ($sec,$min,$hour,$mday,$mon,$year) = (localtime)[0,1,2,3,4,5];
$year=$year+1900;
$mon=$mon+1;

printf("%02d%02d%02d", $year,$mon,$mday);
---


Owen


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Dates

2005-01-07 Thread Scott R. Godin
Jeff Eggen wrote:
Tim Wolak <[EMAIL PROTECTED]> 06/01/2005 3:59:26 pm >>>
Hello all,

I am in need of a quick way to get the current date in the MMDD 
format.  This is something I would like to understand better on how to

get the date with perl.  Any suggestions would be most welcome.
As per the perlcheat page: "just use POSIX::strftime!"
# Begin
use POSIX qw(strftime);
my $date = strftime("%Y%m%d", localtime());
# End
There's possibly something in Date::Calc as well.  But this is the
quickest way I know, especially if you're familiar with the date command
in *nix.
Indeed, this is what I would use myself if I needed to format a unixtime 
string into a particular date format although I prefer %F myself ..

 $ perl -MPOSIX=strftime -le 'print strftime("%F", localtime())'
2005-01-07

%F is the equivalent of %Y-%m-%d which, according to the strftime 
manpage, is the ISO 8601 date format.


I've used this on occasion after returning values from Date::Parse, in 
order to insert the tested valid value in a database, later, but 
reformatted as the db expects to see it.

sub valid_birthday { #object-oriented method
$_[0]->get_birthday() and
return( str2time( $_[0]->{_birthday} ) );
return undef;
}
and once I have a true value returned from the valid_birthday method, I 
can format it with POSIX strftime into what the database expects to see, 
as opposed to whatever the user typed into the form.

It's simple, elegant things like this that make me happy. :)
--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Dates

2005-11-04 Thread Timothy Johnson

Check out the Time::Local module.  It will let you convert your text
date into Perl time() format.

-Original Message-
From: Scott Taylor [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 04, 2005 11:36 AM
To: beginners@perl.org
Subject: Dates


Hello,

I have a date in UT that looks like this:
"2005-11-02 01:36:00.0"

Can anyone tell me the best way to subtract 8 hours from it, or to
convert
it to PDT?





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Dates

2005-11-04 Thread Jeff 'japhy' Pinyan

On Nov 4, Scott Taylor said:


I have a date in UT that looks like this:
"2005-11-02 01:36:00.0"

Can anyone tell me the best way to subtract 8 hours from it, or to convert
it to PDT?

I'm reading up on Date::Manip, but I don't know if that is going to help,
yet.


Date::Manip can probably do it, and it can also cook you a three-course 
meal and help you find your wallet.  For a slightly lighter-weight 
solution, consider the simple Date::Parse (which comes with Perl).  It can 
handle the format you've provided:


  use Date::Parse;
  my $gmtime = str2time("2005-11-02 01:36:00.0", "UTC");

Now you have the number of seconds in $gmtime.  Subtract 8 hours by 
subtracting 60*60*8 seconds from that.


--
Jeff "japhy" Pinyan%  How can we ever be the sold short or
RPI Acacia Brother #734%  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %-- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Dates again.

2005-12-05 Thread Rafael Morales
Hi to all !!!

Now I have a new trouble with dates. How can I know the date of 72 days ago ?. 
For example for get 2005-12-05, I do this

use POSIX qw(strftime);

my $today = strftime "%Y-%m%d", localtime();

I would like to get this date: 2005-09-21.

Thanks list.

-- 
___
Get your free email from http://mymail.bsdmail.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Comparing dates

2006-06-25 Thread ebony smith
I am new to perl and need to compare some dates in a file stored in 
dd-mm- format to find out if the dates are greater than 30, 60 or 90 
days.
However, I am not quite sure how to go about doing that in perl and I was 
wondering if anyone out there had any tips on how to do this.



I extract the data required using the following to get a date and username

if (-e $FILE) { unlink $FILE ;}
open (CHK, ">> $FILE") || die "Cannot open $FILE";

   system (`awk  '/Login/ {print \$1,\$7}' $FILE1 | sort -u  >> 
$FILE1`);



Then this gives me the current date

$tm = localtime($date);
$day = $tm->mday;
$month = $tm->mon+1;
$year = $tm->year+1900;

if ( $day < 10 ){
  $day="0$day";
  }

if ( $month < 10 ){
  $month="0$month";
  }

  $querydate = "$year-$month-$day";
  return $querydate


However I am not too sure how to go about comparing the date extracted from 
the data file with the current date to find out if it is greater 30, 60 or 
90 days.


Any help would be appreciated.

_
Be the first to hear what's new at MSN - sign up to our free newsletters! 
http://www.msn.co.uk/newsletters



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: dates

2006-10-10 Thread Wagner, David --- Senior Programmer Analyst --- WGO
The same you your doing $year, $mon, $mday use %02d which tells
sprintf to add leading zeros as need to keep the size correct. So
\_$hour\:$min\:$sec becomes \_%02d\:%02d\:%02d and you add the $hour,
$min and $sec after the $mday.

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 10, 2006 11:55
To: beginners@perl.org
Subject: dates

Just a quick easy one, while printing localtime, how do I get it to
print the full minutes and seconds, i.e. :02??

Thanks,
Tim

my $date;
my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5];
$year=$year+1900; $mon=$mon+1; $date =
sprintf("%02d%02d%02d\_$hour\:$min\:$sec", $year,$mon,$mday);


--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/>
<http://learn.perl.org/first-response>



**
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.
**


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: dates

2006-10-10 Thread Rob Dixon

Tim Wolak wrote:

Just a quick easy one, while printing localtime, how do I get it to
print the full minutes and seconds, i.e. :02??

Thanks,
Tim

my $date;
my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5];
$year=$year+1900;
$mon=$mon+1;
$date = sprintf("%02d%02d%02d\_$hour\:$min\:$sec", $year,$mon,$mday);



Either

my @date = reverse ((localtime)[0 .. 5]);
$date[0] += 1900;
$date[1]++;
my $date = sprintf "%d%02d%02d_%02d:%02d:%02d", @date;

or

use POSIX qw/strftime/;
my $date = strftime '%Y%m%d_%H:%M:%S', localtime;


Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: dates

2006-10-10 Thread John W. Krahn
Tim Wolak wrote:
> Just a quick easy one, while printing localtime, how do I get it to
> print the full minutes and seconds, i.e. :02??
> 
> Thanks,
> Tim
> 
> my $date;
> my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5];
> $year=$year+1900;
> $mon=$mon+1;
> $date = sprintf("%02d%02d%02d\_$hour\:$min\:$sec", $year,$mon,$mday);

my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime;

my $date = sprintf '%02d%02d%02d_%02d:%02d:%02d', $year + 1900, $mon + 1,
$mday, $hour, $min, $sec;



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Dates subtraction

2001-07-22 Thread Ackim Chisha

Hi Everybody,
Is there a shortcut way to subtract dates say for instance I would like to
be subtracting the current date from the date that the service for  a
particular user expires, say (expiry date -- current date). Or do I have to
write
a specific script for this. Forgive my newbie ignorance.

Kregards,
Ackim.




RE: Dates

2001-09-03 Thread Govinderjit Dhinsa

   
> I want to print a weekly transaction statement using perl. 
> It should ask the user to enter the start date and the end date
> e.g:$start_date = 30/08/01(dd/mm/yy)
>  
> $end_date = 05/09/01
>  This information will filter through a transactions file to print out the
> statement within the given date.
> My program currently has this code:
>  
>if (($day == 17) || ($day == 18) || ($day == 19) || ($day == 20)
> ||($day
>== 21) || ($day == 22) || ($day == 23)){
>  ---
> --
> } 
> 
> Is it possible to use the start and end dates to filter through the data
> e.g, with the given dates above, the program should print statements with
> date 30/08, 31/08, 01/09, 02/09, .
> 
Thanks.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Perl dates

2002-04-03 Thread Ho, Tony

Hi guys,
I was wondering if you could help me.
I have a variable in my perl code called $deadline_date.
I assign $deadline_date the value 20011212. The date format is MMDD.
 
I have a file which contains 2 columns of values i.e. date and product as
follows:
 
20011001 abc
20010701 bcd
20011101 efg
20010201 hij
 
I need to select those rows which has a date less than 3 months before the
$deadline_date i.e. rows 1 and 3
 
How can I use DATE functionalities in perl to do this comparison ?
Any advice would be appreciated.
Thanks in advance
Tony
 



compare dates

2002-05-06 Thread Lance Prais



Hello,
  How do you compare dates to see if dates are "between"?
For example in SQL I would do it like this to find the values between now
and seven days prior:.
X is Between(sysdate-7) and sysdate
Thank you,



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Compare dates

2002-08-14 Thread Shane Laffin

Hello List,

How do I compare two dates in the format:

Thu Aug 15 2002 15:12:02

to return if one date is higher than the other.

Does anyone have any ideas on suitable modules, most
the date modules I have looked at dont deal with this
date format.

Any help or pointers would be great.

Thanks

Shane


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




comparing dates

2002-01-07 Thread Alex Harris



if I use the following to get the date of a file:
use File::stat;
use Time::localtime;
$date_string = ctime(stat($file)->mtime);
print "file $file updated at $date_string\n";

I get:
   Mon Jan  7 10:21:21 2002

Now I want to compare another file date to this one getting the date the 
same way but I don't understand the following example:

sub getdate {
local($_) = shift;
s/-(\d{4})$/+$1/ || s/\+(\d{4})$/-$1/;
# getdate has broken timezone sign reversal!
$_ = `/usr/local/lib/news/newsbin/getdate '$_'`;
chop;
$_;
}

I can't use c modules because they haven't been added and I don't have 
permissions.  TIA

_
Send and receive Hotmail on your mobile device: http://mobile.msn.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Dates

2002-02-01 Thread Nikola Janceski

use Date::Calc module;
man Date::Calc (if it's installed).


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 01, 2002 2:35 PM
To: [EMAIL PROTECTED]
Subject: Dates


this statement
($sec,$min,$hour,$mon,$year,$wday,$yday,$isdst) = localtime();
i obtain the date of today, but i need the $day,$mon,$year of yesterday

How?

Thank you

Argenis Perez
-- 
Nunca creas feliz a nadie que esté pendiente de la felicidad.
Se apoya en una base frágil quien pone su alegría en lo adventicio.
El goce que viene de afuera, afuera se irá.
Por el contrario, aquel que nace de uno mismo
es fiel y firme, y crece, y nos acompaña hasta el fin.

- Lucio Anneo Séneca -



Saludos
Argenis Perez













 






__
Your favorite stores, helpful shopping tools and great gift ideas.
Experience the convenience of buying online with Shop@Netscape!
http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at
http://webmail.netscape.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Dates

2002-02-01 Thread Timothy Johnson


Try this:

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time
-86400); #86400 seconds in a day
print join "-",(($mon + 1),$mday,($year + 1900));

BTW, that's an interesting quote.  If you don't mind my asking, who is Lucio
Anneo Séneca?

-Original Message-
From: Argenis Perez [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 01, 2002 11:35 AM
To: [EMAIL PROTECTED]
Subject: Dates


this statement
($sec,$min,$hour,$mon,$year,$wday,$yday,$isdst) = localtime();
i obtain the date of today, but i need the $day,$mon,$year of yesterday

How?

Thank you

Argenis Perez
-- 
Nunca creas feliz a nadie que esté pendiente de la felicidad.
Se apoya en una base frágil quien pone su alegría en lo adventicio.
El goce que viene de afuera, afuera se irá.
Por el contrario, aquel que nace de uno mismo
es fiel y firme, y crece, y nos acompaña hasta el fin.

- Lucio Anneo Séneca -



Saludos
Argenis Perez













 






__
Your favorite stores, helpful shopping tools and great gift ideas.
Experience the convenience of buying online with Shop@Netscape!
http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at
http://webmail.netscape.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Working with Dates (was: Wroking with Dates)

2003-02-05 Thread Janek Schleicher
On Wed, 05 Feb 2003 22:20:54 +, Thomas Williams wrote:

> I got dates in the -mm-dd format, and I need to compare them to today's 
> date, as well do stuff like date += 2 months.
> 
> How do I do it?

As the other ones already has said, use the Date:: modules for
manipulation. However, if you get the luck that your format is -mm-dd
comparing becomes very simple. (Just use the the lt, gt, le, ge lexical
comparing operators). The today's date in the -mm-dd format could you
get e.g. with

use POSIX qw/strftime/; 
my $today = strftime "%Y-%m-%d", localtime;


Best Wishes,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Dates again.

2005-12-05 Thread vmalik
I am assuming that localtime() returns the time in unix file format (number of
seconds since 12:00 AM on January 01, 1970). Why don't you convert 72 days to
seconds and subtract that number from the output of localtime()? 

For example, 72 days = 72 x 3600 x 24 seconds = 6220800 seconds

So, try:



use POSIX qw(strftime);
 
my $SeventyTwoDaysAgo = strftime "%Y-%m%d", localtime() - 6220800;



or something along these line.



Quoting Rafael Morales <[EMAIL PROTECTED]>:

> Hi to all !!!
> 
> Now I have a new trouble with dates. How can I know the date of 72 days ago
> ?. For example for get 2005-12-05, I do this
> 
> use POSIX qw(strftime);
> 
> my $today = strftime "%Y-%m%d", localtime();
> 
> I would like to get this date: 2005-09-21.
> 
> Thanks list.
> 
> -- 
> ___
> Get your free email from http://mymail.bsdmail.com
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 





This mail sent through www.mywaterloo.ca

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Dates again.

2005-12-05 Thread Timothy Johnson

localtime() returns an array with populated with the details about the
current time and date (unless you feed it a date in Perl time() format).

The key, then is to get your text date into Perl time format.  Some
modules that can help you are Date::Manip, Date::Calc, and Time::Local.
I prefer the last one because it is simpler than the first two (they
handle a lot of things you don't need just for this).  Once you get your
date in Perl time, you can just subtract the requisite number of seconds
to get the date you want.

Of course, if you just want 72 days from right now, it's even easier:

my $dateInThePast = time - 72 * 86400;

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 05, 2005 9:10 AM
To: Rafael Morales
Cc: beginners@perl.org
Subject: Re: Dates again.

I am assuming that localtime() returns the time in unix file format
(number of
seconds since 12:00 AM on January 01, 1970). Why don't you convert 72
days to
seconds and subtract that number from the output of localtime()? 

For example, 72 days = 72 x 3600 x 24 seconds = 6220800 seconds





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Dates again.

2005-12-05 Thread Rafael Morales
I had found a solution:

my $num_day = 72 * 60 * 60 *24;
my $result = $today - $num_day;
my $end = strftime "%Y-%m-%d", localtime($result);

But Timothy, I see that your solution is better :), all in one line.

Thanks to all you.

- Original Message -
From: "Timothy Johnson" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED], "Rafael Morales" <[EMAIL PROTECTED]>
Subject: RE: Dates again.
Date: Mon, 5 Dec 2005 10:32:29 -0800

> 
> 
> localtime() returns an array with populated with the details about the
> current time and date (unless you feed it a date in Perl time() format).
> 
> The key, then is to get your text date into Perl time format.  Some
> modules that can help you are Date::Manip, Date::Calc, and Time::Local.
> I prefer the last one because it is simpler than the first two (they
> handle a lot of things you don't need just for this).  Once you get your
> date in Perl time, you can just subtract the requisite number of seconds
> to get the date you want.
> 
> Of course, if you just want 72 days from right now, it's even easier:
> 
> my $dateInThePast = time - 72 * 86400;
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 05, 2005 9:10 AM
> To: Rafael Morales
> Cc: beginners@perl.org
> Subject: Re: Dates again.
> 
> I am assuming that localtime() returns the time in unix file format
> (number of
> seconds since 12:00 AM on January 01, 1970). Why don't you convert 72
> days to
> seconds and subtract that number from the output of localtime()?
> 
> For example, 72 days = 72 x 3600 x 24 seconds = 6220800 seconds
> 
> 
> 
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>


-- 
___
Get your free email from http://mymail.bsdmail.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Comparing dates

2006-06-25 Thread Anthony Ettinger

Date::Calc


On 6/25/06, ebony smith <[EMAIL PROTECTED]> wrote:

I am new to perl and need to compare some dates in a file stored in
dd-mm- format to find out if the dates are greater than 30, 60 or 90
days.
However, I am not quite sure how to go about doing that in perl and I was
wondering if anyone out there had any tips on how to do this.


I extract the data required using the following to get a date and username

if (-e $FILE) { unlink $FILE ;}
open (CHK, ">> $FILE") || die "Cannot open $FILE";

system (`awk  '/Login/ {print \$1,\$7}' $FILE1 | sort -u  >>
$FILE1`);


Then this gives me the current date

$tm = localtime($date);
$day = $tm->mday;
$month = $tm->mon+1;
$year = $tm->year+1900;

if ( $day < 10 ){
   $day="0$day";
   }

if ( $month < 10 ){
   $month="0$month";
   }

   $querydate = "$year-$month-$day";
   return $querydate


However I am not too sure how to go about comparing the date extracted from
the data file with the current date to find out if it is greater 30, 60 or
90 days.

Any help would be appreciated.

_
Be the first to hear what's new at MSN - sign up to our free newsletters!
http://www.msn.co.uk/newsletters


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>






--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Comparing dates

2006-06-25 Thread John W. Krahn
ebony smith wrote:
> I am new to perl and need to compare some dates in a file stored in
> dd-mm- format to find out if the dates are greater than 30, 60 or 90
> days.
> However, I am not quite sure how to go about doing that in perl and I
> was wondering if anyone out there had any tips on how to do this.
> 
> 
> I extract the data required using the following to get a date and username
> 
> if (-e $FILE) { unlink $FILE ;}
> open (CHK, ">> $FILE") || die "Cannot open $FILE";
> 
>system (`awk  '/Login/ {print \$1,\$7}' $FILE1 | sort -u  >>
> $FILE1`);
> 
> 
> Then this gives me the current date
> 
> $tm = localtime($date);
> $day = $tm->mday;
> $month = $tm->mon+1;
> $year = $tm->year+1900;
> 
> if ( $day < 10 ){
>   $day="0$day";
>   }
> 
> if ( $month < 10 ){
>   $month="0$month";
>   }
> 
>   $querydate = "$year-$month-$day";
>   return $querydate
> 
> 
> However I am not too sure how to go about comparing the date extracted
> from the data file with the current date to find out if it is greater
> 30, 60 or 90 days.


use warnings;
use strict;

use Date::Calc 'Add_Delta_Days';

my ( $today_day, $today_month, $today_year ) = ( localtime )[ 3, 4, 5 ];
$today_month++;
$today_year += 1900;

my $today_minus_30 = sprintf '%04d%02d%02d', Add_Delta_Days $today_year,
$today_month, $today_day, -30;
my $today_minus_60 = sprintf '%04d%02d%02d', Add_Delta_Days $today_year,
$today_month, $today_day, -60;
my $today_minus_90 = sprintf '%04d%02d%02d', Add_Delta_Days $today_year,
$today_month, $today_day, -90;


open CHK, '<', $FILE1 or die "Cannot open '$FILE1' $!";

my %unique;

while (  ) {
next unless /Login/;

my ( $date, $username ) = ( split )[ 0, 6 ];

$date = sprintf '%04d%02d%02d', reverse $date =~ /\d+/g;

$unique{ $date, $username } = ();
}

my @sorted = map [ split $; ], sort keys %unique;

for my $record ( @sorted ) {
if ( $record->[ 0 ] > $today_minus_90 ) {
do_something();
}
if ( $record->[ 0 ] > $today_minus_60 ) {
do_something();
}
if ( $record->[ 0 ] > $today_minus_30 ) {
do_something();
}
}



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Operations with dates

2002-12-26 Thread Marcelo
Hi people ...
I need to erase e-mails based in their dates, when a mail is one month 
old I need to erase it or move it to another folder ... but I don't know 
if I could do operations like :

use Mail::Box::Manager;
$mgr = Mail::Box::Manager->new;
$inbox = "/var/spool/mail/marcelo";
$folder = $mgr->open($inbox);
$msg = $folder->message(3);
$head = $msg->head;
$maildate = $head->get('Date');
@splitdate = split  / /, $maildate;
$mailmonth = $splitdate[1];
$date = localtime;
   $_ = $date;

   /\w+ (\w+) *(\d+) (\d+):(\d+):(\d+) (\d+)/;
   $month=$1;

if ( $mailmonth < $month){
# do something
}


I don't know if that type of operations are permitted or if it gives me 
the right answer ..., and if there is another way to do that please tell 
me how ...Thanks !


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Wroking with Dates

2003-02-05 Thread Thomas Williams
I got dates in the -mm-dd format, and I need to compare them to today's 
date, as well do stuff like date += 2 months.

How do I do it?

Tom

_
Add photos to your e-mail with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Handling Dates Suggestions

2003-10-08 Thread perl
Can someone offers some recommendation into using dates?

I will be referencing year, month,day,hour,min,sec. I will also need to
increment or decrement by hours, days, months and years.

thanks,
-rkl


-
eMail solutions by 
http://www.swanmail.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



dealing with dates

2003-10-28 Thread Steve Main


Hello list,

I am having a problem coming up with a solution to compare and find the
difference between two dates.

One of the dates is a GMT date while the other is PST(or PDT) so my
first
Problem is converting the local date to GMT which is fine unless I want
to automagically "detect" the hour back or ahead.  So I guess my
question is does anyone have a slick way to convert a date to GMT and a
way to get the number of days between the two dates?

Thanks

Steve


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Dates subtraction

2001-07-22 Thread Steve Howard

Have you installed and DATE::CALC. If so you would do something like this:

# use date calc and get the current time into a hash:

use Date::Calc  qw(:all);

my %th;

@th{qw(sec min hour mday mon year wday yday isdst)} = localtime(time);

$th{mon}++;
$th{year} += 1900;

#define the expiatory date (you have to do this for your purpose.

my @expiatory = qw(2002 1 23);

#here's the function you're looking for
#it is a Date::Calc function:

my $dd = Delta_Days(@th{year, mon, mday}, @expiatory);

#print out the difference in days.

print "$dd\n";

You'll have to install Date::Calc and read perldoc Date::Calc to get
familiar with it, but it is a VERY good module for working with dates in any
way I've ever needed to work with them. Delta_Days is only one useful
function it contains. There are numerous others you should be familiar with.

You don't have to use a hash like I did with the localtime function, I just
like working with the hash slices. Customize that to your purpose.

Hope this helps,

Steve Howard

-Original Message-
From: Ackim Chisha [mailto:[EMAIL PROTECTED]]
Sent: Sunday, July 22, 2001 8:50 AM
To: [EMAIL PROTECTED]
Subject: Dates subtraction


Hi Everybody,
Is there a shortcut way to subtract dates say for instance I would like to
be subtracting the current date from the date that the service for  a
particular user expires, say (expiry date -- current date). Or do I have to
write
a specific script for this. Forgive my newbie ignorance.

Kregards,
Ackim.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Dates subtraction

2001-07-22 Thread Jeff 'japhy/Marillion' Pinyan

On Jul 22, Steve Howard said:

>Have you installed and DATE::CALC. If so you would do something like
>this:
>
>my $dd = Delta_Days(@th{year, mon, mday}, @expiatory);

I far prefer the simpler (and standard-module) approach of the Time::Local
module.  This module is a tool you should get to know well.

  use Time::Local;

  my ($bd, $bm, $by) = (9, 11, 1981);  # my birthday
  my ($nd, $nm, $ny) = (localtime)[3..5];  # today

  my $start = timelocal(0,0,12, $bd, $bm-1, $by-1900);  # noon of b'day
  my $end = timelocal(0,0,12, $nd, $nm, $ny);   # noon today

  my $sec_diff = $end - $start;
  my $day_diff = int( $sec_diff / 86400 );

  print "I am $day_diff days old!\n";

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Perl dates

2002-04-03 Thread Timothy Johnson


Check out the Time::Local module.

-Original Message-
From: Ho, Tony [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 03, 2002 8:45 AM
To: [EMAIL PROTECTED]
Subject: Perl dates


Hi guys,
I was wondering if you could help me.
I have a variable in my perl code called $deadline_date.
I assign $deadline_date the value 20011212. The date format is MMDD.
 
I have a file which contains 2 columns of values i.e. date and product as
follows:
 
20011001 abc
20010701 bcd
20011101 efg
20010201 hij
 
I need to select those rows which has a date less than 3 months before the
$deadline_date i.e. rows 1 and 3
 
How can I use DATE functionalities in perl to do this comparison ?
Any advice would be appreciated.
Thanks in advance
Tony
 



This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: compare dates

2002-05-06 Thread Jonathan E. Paton

[Cross-posted reply to cross-posted article... to avoid]
[further duplication only '[EMAIL PROTECTED]' should  ]
[be used for further correspondence on this thread.]
[Remove PBML from the header before replying!  Jonathan]

Hi,

Please don't cross post questions between PBML and [EMAIL PROTECTED]  All my 
beginners mail gets
filtered into the same folder, and it's obvious and annoying to see cross posts.  
You'll find
either list is active enough to have most questions answered within a few hours.  
Cross posting is
a waste of time, when people spend time re-answering questions others already give 
answers to -
but didn't see because they were posted on a different list.

This is again another commonly asked question upon these lists, so you may wish to 
look at:

http://perldoc.com/perl5.6.1/pod/perlfaq4.html#Data--Dates

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: compare dates

2002-05-06 Thread Sean O'Leary

On Mon, 2002-05-06 at 13:53, Lance Prais wrote:
> 
> 
> Hello,
>   How do you compare dates to see if dates are "between"?
> For example in SQL I would do it like this to find the values between now
> and seven days prior:.
> X is Between(sysdate-7) and sysdate
> Thank you,
> 

Use a Date:: module to make sure it's valid date and all that jazz.  I'd
use Date::Calc because it's fairly fast, as far as the Date modules go,
and has a recipe for doing exactly what you described.  Check out the
Date::Calc here:

http://search.cpan.org/doc/STBEY/Date-Calc-5.0/Calc.pod

Later,

Sean.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: calculate dates

2002-05-28 Thread drieux


On Tuesday, May 28, 2002, at 09:25 , Sven Bentlage wrote:

> Hi !
> I'm trying to get all the date values for the week (7days) ahead of a 
> specified date.
> To get the current date I use :   
>   my ($d, $m, $y) = (localtime)[3,4,5];
>   my $date = sprintf("%02d-%02d-%02d", 
>$d, $m+1, $y-100);
> To get the date of the date 7 days ahead I use:
>   my ($da, $ma, $ya) = (localtime (time+ 
>(7*24*60*60)))[3,4,5];
>   my $next_date = 
>sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);


your friend the loop would help here.

use constant SECONDS_PER_DAY(24*60*60);

my $day_ahead = 1;
my $max_day_ahead = 7;

for (; $day_ahead <= $max_day_ahead ; $day_ahead++ )
{
my $tmp_t =( $day_ahead * SECONDS_PER_DAY);
my ($da, $ma, $ya) = (localtime(time + $tmp_t))[3,4,5];
my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);

}


you may want to do the perldoc on constant - since this
will help you with more on how to think about writing
self documenting code

ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: calculate dates

2002-05-28 Thread Felix Geerinckx

on Tue, 28 May 2002 17:53:27 GMT, Drieux wrote:

>  use constant SECONDS_PER_DAY (24*60*60);
> [...]
> you may want to do the perldoc on constant - since this
> will help you with more on how to think about writing
> self documenting code

You may want to take a look yourself, since your syntax is wrong ;-)

use constant SECONDS_PER_DAY => (24*60*60);

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: calculate dates

2002-05-28 Thread John W. Krahn

Drieux wrote:
> 
> On Tuesday, May 28, 2002, at 09:25 , Sven Bentlage wrote:
> 
> > I'm trying to get all the date values for the week (7days) ahead of a
> > specified date.
> > To get the current date I use :
> > my ($d, $m, $y) = (localtime)[3,4,5];
> > my $date = sprintf("%02d-%02d-%02d", $d, $m+1, $y-100);
   ^^

> > To get the date of the date 7 days ahead I use:
> > my ($da, $ma, $ya) = (localtime (time+ (7*24*60*60)))[3,4,5];
> > my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);
  ^^^
You shouldn't subtract 100 from the year returned from localtime, it
won't work with all dates, use modulus instead.  $year % 100


> your friend the loop would help here.
> 
> use constant SECONDS_PER_DAY(24*60*60);
> 
> my $day_ahead = 1;
> my $max_day_ahead = 7;
> 
> for (; $day_ahead <= $max_day_ahead ; $day_ahead++ )
> {
> my $tmp_t =( $day_ahead * SECONDS_PER_DAY);
> my ($da, $ma, $ya) = (localtime(time + $tmp_t))[3,4,5];
> my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);
> 
> }


use POSIX 'strftime';

print strftime '%d-%m-%y%n', localtime time + $_ * 86_400 for 0 .. 6;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Compare dates

2002-08-15 Thread Felix Geerinckx

on Thu, 15 Aug 2002 05:05:15 GMT, Shane Laffin wrote:

>  How do I compare two dates in the format:
> 
>   Thu Aug 15 2002 15:12:02
> 
>  to return if one date is higher than the other.
> 
> Does anyone have any ideas on suitable modules, most
> the date modules I have looked at dont deal with this
> date format.

Roll your own:

#! perl -w
use strict;

my $date1 = "Thu Aug 15 2002 15:12:02";
my $date2 = "Wed Jul 10 2002 10:10:10";


print cmp_dates($date1, $date2), "\n"; # prints 1
print cmp_dates($date2, $date1), "\n"; # prints -1
print cmp_dates($date1, $date1), "\n"; # prints 0

BEGIN {
  my %months = (Jan => '01', Feb => '02', Mar => '03', Apr => '04',
May => '05', Jun => '06', Jul => '07', Aug => '08',
Sep => '09', Oct => '10', Nov => '11', Dec => '12' );


  sub cmp_dates {
  my @d1 = (split " ", shift)[3,1,2,4];
  my @d2 = (split " ", shift)[3,1,2,4];

  $d1[1] = $months{$d1[1]};
  $d2[1] = $months{$d2[1]};

  return (join "", @d1) cmp (join "", @d2);
 }
   }


-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Compare dates

2002-08-15 Thread Robin Norwood

"Shane Laffin" <[EMAIL PROTECTED]> writes:

> Hello List,
> 
>   How do I compare two dates in the format:
> 
>   Thu Aug 15 2002 15:12:02
> 
>   to return if one date is higher than the other.
> 
> Does anyone have any ideas on suitable modules, most
> the date modules I have looked at dont deal with this
> date format.
> 
> Any help or pointers would be great.

Sure,

'
#!/usr/bin/perl -w

use Date::Parse;

my $time = str2time("Thu Aug 15 2002 15:12:02");  #now in 'unixtime'
print $time;#   '1029438722'
print scalar localtime($time);  #   'Thu Aug 15 15:12:02 2002'
'

Run both your dates through Date::Parse, and compare them numerically.

Good enough?

-RN

-- 

Robin Norwood
Red Hat, Inc.

"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Compare dates

2002-08-16 Thread Janek Schleicher

Shane Laffin wrote at Thu, 15 Aug 2002 07:05:15 +0200:

>   How do I compare two dates in the format:
> 
>   Thu Aug 15 2002 15:12:02
> 
>   to return if one date is higher than the other.
> 
> Does anyone have any ideas on suitable modules, most
> the date modules I have looked at dont deal with this
> date format.

use Date::Manip;

my $start = ParseDate("Thu Aug 15 2002 15:12:02");
my $end   = ParseDate("Thu Aug 16 2002 15:12:02");

if (Date_Cmp($start, $end) <= 0) {
   print "The start is before the end.";
}


Greetings,
Janek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Subtracting Zero Dates

2004-06-18 Thread Werner Otto
Hi All,
Does anyone know how to handle subtracting two dates where one might be 0 
or no time or blank?

--
Kind Regards,
Werner Otto
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: comparing dates

2002-01-07 Thread Matt C.

Check out Date::Manip; it can do just about anything you'd need to do with dates. If
speed is of great concern (I use Date::Manip and it performs fine), you may be able
to find another Date::* module more specifically tuned to your needs. 

Definitely try Date::Manip first though, as it will work for you. Plus it's easy and
well documented. Looks like you'd want to stat both of your files, then pass the
dates into Date::Manip, where you can do whatever with it.

Matt

--- Alex Harris <[EMAIL PROTECTED]> wrote:
> 
> 
> if I use the following to get the date of a file:
> use File::stat;
> use Time::localtime;
> $date_string = ctime(stat($file)->mtime);
> print "file $file updated at $date_string\n";
> 
> I get:
>Mon Jan  7 10:21:21 2002
> 
> Now I want to compare another file date to this one getting the date the 
> same way but I don't understand the following example:
> 
> sub getdate {
>   local($_) = shift;
>   s/-(\d{4})$/+$1/ || s/\+(\d{4})$/-$1/;
>   # getdate has broken timezone sign reversal!
>   $_ = `/usr/local/lib/news/newsbin/getdate '$_'`;
>   chop;
>   $_;
> }
> 
> I can't use c modules because they haven't been added and I don't have 
> permissions.  TIA
> 
> _
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


__
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: comparing dates

2002-01-07 Thread Yacketta, Ronald

how about converting the times to epoch time and then compare?
have a look at timelocal to convert to epoch time

> -Original Message-
> From: Alex Harris [mailto:[EMAIL PROTECTED]]
> Sent: Monday, January 07, 2002 11:38
> To: [EMAIL PROTECTED]
> Subject: comparing dates
> 
> 
> 
> 
> if I use the following to get the date of a file:
> use File::stat;
> use Time::localtime;
> $date_string = ctime(stat($file)->mtime);
> print "file $file updated at $date_string\n";
> 
> I get:
>Mon Jan  7 10:21:21 2002
> 
> Now I want to compare another file date to this one getting 
> the date the 
> same way but I don't understand the following example:
> 
> sub getdate {
>   local($_) = shift;
>   s/-(\d{4})$/+$1/ || s/\+(\d{4})$/-$1/;
>   # getdate has broken timezone sign reversal!
>   $_ = `/usr/local/lib/news/newsbin/getdate '$_'`;
>   chop;
>   $_;
> }
> 
> I can't use c modules because they haven't been added and I 
> don't have 
> permissions.  TIA
> 
> _
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: comparing dates

2002-01-07 Thread John W. Krahn

Alex Harris wrote:
> 
> if I use the following to get the date of a file:
> use File::stat;
> use Time::localtime;
> $date_string = ctime(stat($file)->mtime);
> print "file $file updated at $date_string\n";
> 
> I get:
>Mon Jan  7 10:21:21 2002
> 
> Now I want to compare another file date to this one getting the date the
> same way but I don't understand the following example:
> 
> [snip]

my $date1 = stat( $file1 )->mtime;
my $date2 = stat( $file2 )->mtime;

if ( $date1 < $date2 ) {
print "$file1 is older than $file2\n";
}
elsif ( $date2 < $date1 ) {
print "$file2 is older than $file1\n";
}
else {
print "$file1 and $file2 were modified at the same time.\n";
}


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Fianacial Julian Dates

2002-01-17 Thread Mark Martin

Hi,
I'm trying to use the Time::JulianDay module to work with Julian Dates.
However the dates are in a Financial system where today - 17/01/02 is
represented by the Julian Date 102017. Any Julian Date calendee though will
tell you today is 2452291.5

I'm lost  - does anybodsy have any ideas?
Mark

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Dates Perl & SQL7

2002-02-20 Thread Mason, Andrew

This is a concept question rather than a code question.

I have a script which produces a simple report on some simple disk space
stats for servers I work with.
I thought it would be useful to put this information into a database on
a daily basis.  This would allow me to then look at historic data.

Currently I am inserting the date a character string.  I have learned
that while I can do this I greatly limit my capabilities at the SQL end.
SQL7 uses a number to represent date and time.  I am sure that Perl does
(or at least) can also treat numbers like this.

Can anyone suggest what commands (or even modules) I should look up,
relating to dates and times and conversion between different formats (Ie
useful ones for manipulation vs human recognisable ones).

TAI

&rw

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




script to compare dates

2009-08-18 Thread Mihir Kamdar
Hi,

I want to write a script whose input data would be a csv file and records
would be as follows:-

60020003076570*,2,*20-SEP-08.01:09:18,,*04-NOV-08*
,1,INR,,VOUCHER_BATCH_20080919_00014,2C,,0
326495*,5,*20-SEP-08.01:09:57,,*31-DEC-09*
,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
327480,*2,*20-SEP-08.01:09:57,,*31-DEC-08*
,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0

Here I want to compare whether the 5th field, which is the date field
is *earlier
than 31-Mar-09 and 2nd field value is 2.*

If yes, then I will take that record and store it in another file.

Please help me as to how do I compare dates, preferably with some sample
code.

I started coding for this as below, but am stuck on how to compare date in
my input with another date.

#!/usr/bin/perl
use strict;
use warnings ;

open (my $IN_FILE,"<","testdata.txt") or die $!." file not found" ;
while (my $line=readline($IN_FILE))
{
my @cdr=split (/,/, $line) ;
if($cdr[5]
.
.
}

Thanks,
Mihir


Re: Re: Dates again.

2005-12-05 Thread Beau E. Cox
Hi vmalik -
  
At 2005-12-05, 07:09:51 you wrote:
>I am assuming that localtime() returns the time in unix file format (number of
>seconds since 12:00 AM on January 01, 1970). Why don't you convert 72 days to
>seconds and subtract that number from the output of localtime()? 

No. time() returns epoch seconds ( seconds since 1-1-70 ), localtime() returns
an array or formatted scalar. See perldoc -f time, localtime.

>
>For example, 72 days = 72 x 3600 x 24 seconds = 6220800 seconds
>
>So, try:
>
>
>
>use POSIX qw(strftime);
> 
>my $SeventyTwoDaysAgo = strftime "%Y-%m%d", localtime() - 6220800;
>
>
>
>or something along these line.
>
>
>
>Quoting Rafael Morales <[EMAIL PROTECTED]>:
>
>> Hi to all !!!
>> 
>> Now I have a new trouble with dates. How can I know the date of 72 days ago
>> ?. For example for get 2005-12-05, I do this
>> 
>> use POSIX qw(strftime);
>> 
>> my $today = strftime "%Y-%m%d", localtime();
>> 
>> I would like to get this date: 2005-09-21.
>> 
>> Thanks list.
>> 
>> -- 
>> ___
>> Get your free email from http://mymail.bsdmail.com
>> 
>> -- 
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>> 
>> 
>> 
>
>
>
>
>
>This mail sent through www.mywaterloo.ca
>
>-- 
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
><http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
>
>-- 
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.1.362 / Virus Database: 267.13.11/191 - Release Date: 12/2/2005
>



Aloha => Beau;
[EMAIL PROTECTED]
2005-12-05



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Operations with dates

2002-12-26 Thread Wagner, David --- Senior Programmer Analyst --- WGO
If you can get the date as stated, I think you would be better off
taking that date and coming up with seconds from your header and then
compare against the current day - 30 days.  Your test for what I assume is
alphanumeric month(ie, Apr, May, etc) would not work as you expect.

SO if you can get the date in format 26 dec 2002 12:14:00 then you
can come up with the date in seconds and then compare against 30 days(ie, my
$My30DaysPass = time - ( 86400 * 30); ). Then  you can numerically
compare(ie, if ( $MyMailDateSecs < $My30DaysPass ) { # older than 30 days
)else {#not older than 30 days}

A start, but always can provide more if you provide more.

Wags ;)


-Original Message-
From: Marcelo [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:32
To: [EMAIL PROTECTED]
Subject: Operations with dates 


Hi people ...
I need to erase e-mails based in their dates, when a mail is one month 
old I need to erase it or move it to another folder ... but I don't know 
if I could do operations like :

use Mail::Box::Manager;
$mgr = Mail::Box::Manager->new;
$inbox = "/var/spool/mail/marcelo";
$folder = $mgr->open($inbox);
$msg = $folder->message(3);
$head = $msg->head;
$maildate = $head->get('Date');
@splitdate = split  / /, $maildate;
$mailmonth = $splitdate[1];
$date = localtime;
$_ = $date;

/\w+ (\w+) *(\d+) (\d+):(\d+):(\d+) (\d+)/;
$month=$1;

if ( $mailmonth < $month){
# do something
}


I don't know if that type of operations are permitted or if it gives me 
the right answer ..., and if there is another way to do that please tell 
me how ...Thanks !


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


**
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.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Wroking with Dates

2003-02-05 Thread Timothy Johnson

Check out the Date::Calc module.  I think it does what you want.

-Original Message-
From: Thomas Williams [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 05, 2003 2:21 PM
To: [EMAIL PROTECTED]
Subject: Wroking with Dates


I got dates in the -mm-dd format, and I need to compare them to today's 
date, as well do stuff like date += 2 months.

How do I do it?

Tom

_
Add photos to your e-mail with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Wroking with Dates

2003-02-05 Thread david
Thomas Williams wrote:

> I got dates in the -mm-dd format, and I need to compare them to
> today's date, as well do stuff like date += 2 months.
> 
> How do I do it?

check out Date::Manip. Example:

#!/usr/bin/perl -w
use strict;

use Date::Manip;

my $date1 = ParseDate("2003-02-05"); #-- 02/05/2003
my $date2 = ParseDate("2 months");   #-- 2 months from now
my $date3 = ParseDate("now");#-- now

print "$date1\n";
print "$date2\n";
print "$date3\n";

#-- compare
if(Date_Cmp($date2,$date3) == 1){
print "$date2 > $date3\n";
}else{
print "$date2 <= $date3\n";
}

__END__

prints:

2003020500:00:00
2003040514:55:29
2003020514:55:29
2003040514:55:29 > 2003020514:55:29

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Handling Dates Suggestions

2003-10-08 Thread Tore Aursand
On Wed, 08 Oct 2003 17:56:03 -0700, perl wrote:
> Can someone offers some recommendation into using dates?

Take a look at CPAN [1] for Date-related modules.  My personal favorite
has become Time::Piece, although all the Date::* modules should be looked
upon.

[1] http://www.cpan.org/>


-- 
Tore Aursand <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: dealing with dates

2003-10-28 Thread Tim Johnson

You could always use something like Time::Local to break the dates down to
time() format and then subtract 8 hours or whatever you need to do, then
subtract one date from the other.

-Original Message-
From: Steve Main [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 10:15 AM
To: [EMAIL PROTECTED]
Subject: dealing with dates




Hello list,

I am having a problem coming up with a solution to compare and find the
difference between two dates.

One of the dates is a GMT date while the other is PST(or PDT) so my first
Problem is converting the local date to GMT which is fine unless I want to
automagically "detect" the hour back or ahead.  So I guess my question is
does anyone have a slick way to convert a date to GMT and a way to get the
number of days between the two dates?

Thanks

Steve


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: dealing with dates

2003-10-28 Thread Harter, Douglas
Do a search on www.cpan.org for Date::Pcalc. This is a whole series of Perl functions 
dealing with date calculations. (And I didn't even write them.)



> -Original Message-
> From: Steve Main [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, October 28, 2003 1:15 PM
> To: [EMAIL PROTECTED]
> Subject: dealing with dates
> 
> 
> 
> 
> Hello list,
> 
> I am having a problem coming up with a solution to compare 
> and find the
> difference between two dates.
> 
> One of the dates is a GMT date while the other is PST(or PDT) so my
> first
> Problem is converting the local date to GMT which is fine 
> unless I want
> to automagically "detect" the hour back or ahead.  So I guess my
> question is does anyone have a slick way to convert a date to 
> GMT and a
> way to get the number of days between the two dates?
> 
> Thanks
> 
> Steve
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: dealing with dates

2003-10-28 Thread Steve Main
Thanks for the response.

I have been using Date::Pcalc but I guess what I have been unable to
find is an example of how to get the localtime from the system in GMT
format, with the offset already applied.  As I understand as the local
time falls back an hour or springs ahead the offset will change and I
would like to find a way for my program to automagiclly deal with it.
If Pcalc can do this then I haven't been able to figure it out.

thanks

-Original Message-
From: Harter, Douglas [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 11:58 AM
To: Steve Main; [EMAIL PROTECTED]
Subject: RE: dealing with dates

Do a search on www.cpan.org for Date::Pcalc. This is a whole series of
Perl functions dealing with date calculations. (And I didn't even write
them.)



> -Original Message-
> From: Steve Main [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, October 28, 2003 1:15 PM
> To: [EMAIL PROTECTED]
> Subject: dealing with dates
> 
> 
> 
> 
> Hello list,
> 
> I am having a problem coming up with a solution to compare 
> and find the
> difference between two dates.
> 
> One of the dates is a GMT date while the other is PST(or PDT) so my
> first
> Problem is converting the local date to GMT which is fine 
> unless I want
> to automagically "detect" the hour back or ahead.  So I guess my
> question is does anyone have a slick way to convert a date to 
> GMT and a
> way to get the number of days between the two dates?
> 
> Thanks
> 
> Steve
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Comparing Dates Conditional statements

2003-05-27 Thread Paul Kraus
How can I have condition as such

$date = 'XX/XX/XX'; <-insert any date
If $date is greater then 01/01/02 then do .
Else 


Paul


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



regex question matching dates

2008-05-28 Thread Richard Lee

given then ARGV[0] is 2008052803, why woulnd't below regex match them??

} elsif ( $ARGV[0] =~ m/\b2008[01][1-31]([01][0-9]|2[0-3])\b/ ) {
 @array = qx#ls -tr $directory/$ARGV[0]*#;
 #2008052803

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: calculate dates / regex

2002-05-28 Thread Sven Bentlage

Encountered another problem:

I'm trying to use a calculated date value in a regex. It only works with 
values which are NOT calculated.
my ($dc, $mc, $yc) = (localtime(time))[3,4,5];
 my $date_now = sprintf("%02d-%02d-%02d", $dc, $mc+1, 
$yc-100);

my ($da, $ma, $ya) = (localtime (time + (ONE_DAY)))[3,4,5];
my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, 
$ya-100);

using $date_now in this regex works:
while () {
( $date_today, $aponame, $apoaddress, $apotel) = 
split(/:/,$_);
my @data = split(/:/);
foreach ($data[0]) {
if (/$date_now/) { 
 
print "$date_now\n";
print "$next_date\n";
   }
}

if I replace $date_now with $next_date I get an error message (premature 
end of script headers).

Does anybody know how?

Thanks for your tips in advance.

Sven


On Tuesday, May 28, 2002, at 07:53 PM, drieux wrote:

>
> On Tuesday, May 28, 2002, at 09:25 , Sven Bentlage wrote:
>
>> Hi !
>> I'm trying to get all the date values for the week (7days) ahead of a 
>> specified date.
>> To get the current date I use :  
>>  my ($d, $m, $y) = (localtime)[3,4,5];
>>  my $date = sprintf("%02d-%02d-%02d", 
>$d, $m+1, $y-100);
>> To get the date of the date 7 days ahead I use:
>>  my ($da, $ma, $ya) = (localtime (time+ 
>(7*24*60*60)))[3,4,5];
>>  my $next_date = 
>sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);
>
>
> your friend the loop would help here.
>
>   use constant SECONDS_PER_DAY(24*60*60);
>
>   my $day_ahead = 1;
>   my $max_day_ahead = 7;
>
>   for (; $day_ahead <= $max_day_ahead ; $day_ahead++ )
>   {
>   my $tmp_t =( $day_ahead * SECONDS_PER_DAY);
>   my ($da, $ma, $ya) = (localtime(time + $tmp_t))[3,4,5];
>   my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);
>   
>   }
>
>
> you may want to do the perldoc on constant - since this
> will help you with more on how to think about writing
> self documenting code
>
> ciao
> drieux
>
> ---
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: calculate dates / regex

2002-05-28 Thread John W. Krahn

Sven Bentlage wrote:
> 
> Encountered another problem:
> 
> I'm trying to use a calculated date value in a regex. It only works with
> values which are NOT calculated.
> 
> my ($dc, $mc, $yc) = (localtime(time))[3,4,5];
> my $date_now = sprintf("%02d-%02d-%02d", $dc, $mc+1, $yc-100);
   ^^^

> my ($da, $ma, $ya) = (localtime (time + (ONE_DAY)))[3,4,5];
> my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);
^^^
Use $year % 100 instead of subtracting 100.

> using $date_now in this regex works:
> 
> while (  ) {
> ( $date_today, $aponame, $apoaddress, $apotel ) = split(/:/,$_);
> my @data = split(/:/);

Any reason that you are splitting $_ twice?

> foreach ($data[0]) {

Any reason that you are looping over a single scalar?

> if (/$date_now/) {

Maybe you should use eq instead of a regular expression.

> print "$date_now\n";
> print "$next_date\n";
> }
> }
  ^
Missing the while loop end brace.

> 
> if I replace $date_now with $next_date I get an error message (premature
> end of script headers).

They are both formatted the same so they should both work.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: calculate dates / regex

2002-05-29 Thread Sven Bentlage





Encountered another problem:

I'm trying to use a calculated date value in a regex. It only works with 
values which are NOT calculated.
my ($dc, $mc, $yc) = (localtime(time))[3,4,5];
 my $date_now = sprintf("%02d-%02d-%02d", $dc, $mc+1, 
$yc-100);

my ($da, $ma, $ya) = (localtime (time + (ONE_DAY)))[3,4,5];
my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, 
$ya-100);

using $date_now in this regex works:
while () {
( $date_today, $aponame, $apoaddress, $apotel) = 
split(/:/,$_);
my @data = split(/:/);
foreach ($data[0]) {
if (/$date_now/) { 
 
print "$date_now\n";
print "$next_date\n";
   }
}

if I replace $date_now with $next_date I get an error message (premature 
end of script headers).

Does anybody know how?

Thanks for your tips in advance.

Sven
>   
>   
> On Tuesday, May 28, 2002, at 07:53 PM, drieux wrote:
>
>>
>> On Tuesday, May 28, 2002, at 09:25 , Sven Bentlage wrote:
>>
>>> Hi !
>>> I'm trying to get all the date values for the week (7days) ahead of a 
>>> specified date.
>>> To get the current date I use : 
>>> my ($d, $m, $y) = (localtime)[3,4,5];
>>> my $date = sprintf("%02d-%02d-%02d", 
>$d, $m+1, $y-100);
>>> To get the date of the date 7 days ahead I use:
>>> my ($da, $ma, $ya) = (localtime (time+ 
>(7*24*60*60)))[3,4,5];
>>> my $next_date = 
>sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);
>>
>>
>> your friend the loop would help here.
>>
>>  use constant SECONDS_PER_DAY(24*60*60);
>>
>>  my $day_ahead = 1;
>>  my $max_day_ahead = 7;
>>
>>  for (; $day_ahead <= $max_day_ahead ; $day_ahead++ )
>>  {
>>  my $tmp_t =( $day_ahead * SECONDS_PER_DAY);
>>  my ($da, $ma, $ya) = (localtime(time + $tmp_t))[3,4,5];
>>  my $next_date = sprintf("%02d-%02d-%02d", $da, $ma+1, $ya-100);
>>  
>>  }
>>
>>
>> you may want to do the perldoc on constant - since this
>> will help you with more on how to think about writing
>> self documenting code
>>
>> ciao
>> drieux
>>
>> ---
>>
>>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: calculate dates / regex

2002-05-29 Thread Felix Geerinckx

on Wed, 29 May 2002 12:05:45 GMT, [EMAIL PROTECTED] (Sven
Bentlage) wrote: 

> Encountered another problem:
> [...]

Why are you posting the exact same question as yesterday?
Why didn't you take John's advice into account? Did you miss his reply?

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Subtracting Zero Dates

2004-06-18 Thread Tim Johnson
One way:  Convert both dates to Perl time() format, then subtract.

-Original Message- 
From: Werner Otto [mailto:[EMAIL PROTECTED] 
Sent: Fri 6/18/2004 3:28 AM 
To: [EMAIL PROTECTED] 
Cc: 
Subject: Subtracting Zero Dates



Hi All,

Does anyone know how to handle subtracting two dates where one might be 0
or no time or blank?





Re: Subtracting Zero Dates

2004-06-18 Thread Werner Otto
they are all ready in time format, that is the problem.
Example:
$time1 = Date_to_Time($year,$month,$day, $hour,$min,$sec);
$time2 = Date_to_Time($year,$month,$day, $hour,$min,$sec);
$difference = $time1 - $time2;
One way:  Convert both dates to Perl time() format, then subtract.
-Original Message-
From: Werner Otto [mailto:[EMAIL PROTECTED]
Sent: Fri 6/18/2004 3:28 AM
To: [EMAIL PROTECTED]
Cc:
Subject: Subtracting Zero Dates


	Hi All,
	
	Does anyone know how to handle subtracting two dates where one might be 
0
	or no time or blank?
	
	


--
Kind Regards,
Werner Otto
Web/Programming Support
Department of Computer Science
Kings College
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



RE: Subtracting Zero Dates

2004-06-18 Thread Tim Johnson
How about:
 
if($time1 > $time2){
   $difference = $time1 - $time2;
}else{
   die "Invalid date!\n";
}

-Original Message- 
From: Werner Otto [mailto:[EMAIL PROTECTED] 
Sent: Fri 6/18/2004 5:34 AM 
To: Tim Johnson; [EMAIL PROTECTED] 
Cc: 
Subject: Re: Subtracting Zero Dates



they are all ready in time format, that is the problem.

Example:
$time1 = Date_to_Time($year,$month,$day, $hour,$min,$sec);
$time2 = Date_to_Time($year,$month,$day, $hour,$min,$sec);

$difference = $time1 - $time2;

> One way:  Convert both dates to Perl time() format, then subtract.
>
>   -Original Message-
>   From: Werner Otto [mailto:[EMAIL PROTECTED]
>   Sent: Fri 6/18/2004 3:28 AM
>   To: [EMAIL PROTECTED]
>   Cc:
>   Subject: Subtracting Zero Dates
>  
>  
>
>   Hi All,
>  
>   Does anyone know how to handle subtracting two dates where one might be
> 0
>   or no time or blank?
>  
>  
>



--
Kind Regards,
Werner Otto
Web/Programming Support
Department of Computer Science
Kings College




Dates are killing me..

2004-07-07 Thread Chris Puccio
Hi Guys,

I'm having a real hard time trying to figure this out..

There are tons of modules on dates, etc, but I can't seem to find one to do 
what I need.

I have one date, for example: 2004-07-07.

I need to take that date, get Monday's date and Sunday's date where 2004-07-07 
is between.

Any suggestions?

Thanks!!
-c


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Dates Perl & SQL7

2002-02-20 Thread mike

On Wed, 2002-02-20 at 11:26, Mason, Andrew wrote:
> This is a concept question rather than a code question.
> 
> I have a script which produces a simple report on some simple disk space
> stats for servers I work with.
> I thought it would be useful to put this information into a database on
> a daily basis.  This would allow me to then look at historic data.
> 
> Currently I am inserting the date a character string.  I have learned
> that while I can do this I greatly limit my capabilities at the SQL end.
> SQL7 uses a number to represent date and time.  I am sure that Perl does
> (or at least) can also treat numbers like this.
> 
> Can anyone suggest what commands (or even modules) I should look up,
> relating to dates and times and conversion between different formats (Ie
> useful ones for manipulation vs human recognisable ones).

>From experience with SQL7 I would convert your character strings to iso
dates first ie:10/12/2001 to 20011210 then SQL7 will be able to handle
them

assuming date is dd/mm/

split /'/'/;
print $2$1$0

etc

then should be an easy import

(yes very quick and dirty)
> TAI
> 
> &rw
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




difference between 2 dates

2002-03-27 Thread Roy Peters

What is the best way to get the difference betwen 2 dates that I obtain
from localtime

I want to do something like 

$t1=localtime();

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: script to compare dates

2009-08-18 Thread Steve Bertrand
Mihir Kamdar wrote:
> Hi,
> 
> I want to write a script whose input data would be a csv file and records
> would be as follows:-
> 
> 60020003076570*,2,*20-SEP-08.01:09:18,,*04-NOV-08*
> ,1,INR,,VOUCHER_BATCH_20080919_00014,2C,,0
> 326495*,5,*20-SEP-08.01:09:57,,*31-DEC-09*
> ,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
> 327480,*2,*20-SEP-08.01:09:57,,*31-DEC-08*
> ,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
> 
> Here I want to compare whether the 5th field, which is the date field
> is *earlier
> than 31-Mar-09 and 2nd field value is 2.*
> 
> If yes, then I will take that record and store it in another file.
> 
> Please help me as to how do I compare dates, preferably with some sample
> code.
> 
> I started coding for this as below, but am stuck on how to compare date in
> my input with another date.
> 
> #!/usr/bin/perl
> use strict;
> use warnings ;
> 
> open (my $IN_FILE,"<","testdata.txt") or die $!." file not found" ;
> while (my $line=readline($IN_FILE))
> {
> my @cdr=split (/,/, $line) ;
> if($cdr[5]
> .
> .
> }

For fun, and to try out a few things I came across in Damian's book. I
use DateTime to manage all aspects of dates and times. The code below
assumes that all records will always be in the exact same format.
Criticism welcome:


#!/usr/bin/perl

use strict;
use warnings;

use DateTime::Format::Strptime;

my $EXTRACTION_LAYOUT = '@16 A1 @40 A9';

VOUCHER_RECORD:

while ( my $record =  ) {

my ( $important_num, $date_string )
= unpack $EXTRACTION_LAYOUT, $record;

next VOUCHER_RECORD if $important_num != 2;

my $static_date = DateTime->new(
year => 2009,
month => 3,
day => 31
);


# turn the extracted date string into a DateTime object

my $date_formatter
= new DateTime::Format::Strptime( pattern => '%d-%b-%y' );

my $voucher_date
= $date_formatter->parse_datetime($date_string);


# compare the DateTime compiled dates

if ( DateTime->compare( $static_date, $voucher_date )) {

print "Voucher ${voucher_date} is prior to ${static_date}" .
  " and the important number is 2\n";
}
}

__DATA__
60020003076570*,2,*20-SEP-08.01:09:18,,*04-NOV-08*,1,INR,,VOUCHER_BATCH_20080919_00014,2C,,0
326495*,5,*20-SEP-08.01:09:57,,*31-DEC-09*,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
327480,*2,*20-SEP-08.01:09:57,,*31-DEC-08*,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0

Steve


smime.p7s
Description: S/MIME Cryptographic Signature


Re: script to compare dates

2009-08-18 Thread Mihir Kamdar
I dont have Datetime module installed. Is there a way without using
DateTime??

On Tue, Aug 18, 2009 at 7:37 AM, Steve Bertrand  wrote:

>  Mihir Kamdar wrote:
> > Hi,
> >
> > I want to write a script whose input data would be a csv file and records
> > would be as follows:-
> >
> > 60020003076570*,2,*20-SEP-08.01:09:18,,*04-NOV-08*
> > ,1,INR,,VOUCHER_BATCH_20080919_00014,2C,,0
> > 326495*,5,*20-SEP-08.01:09:57,,*31-DEC-09*
> > ,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
> > 327480,*2,*20-SEP-08.01:09:57,,*31-DEC-08*
> > ,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
> >
> > Here I want to compare whether the 5th field, which is the date field
> > is *earlier
> > than 31-Mar-09 and 2nd field value is 2.*
> >
> > If yes, then I will take that record and store it in another file.
> >
> > Please help me as to how do I compare dates, preferably with some sample
> > code.
> >
> > I started coding for this as below, but am stuck on how to compare date
> in
> > my input with another date.
> >
> > #!/usr/bin/perl
> > use strict;
> > use warnings ;
> >
> > open (my $IN_FILE,"<","testdata.txt") or die $!." file not found" ;
> > while (my $line=readline($IN_FILE))
> > {
> >     my @cdr=split (/,/, $line) ;
> > if($cdr[5]
> > .
> > .
> > }
>
> For fun, and to try out a few things I came across in Damian's book. I
> use DateTime to manage all aspects of dates and times. The code below
> assumes that all records will always be in the exact same format.
> Criticism welcome:
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use DateTime::Format::Strptime;
>
> my $EXTRACTION_LAYOUT = '@16 A1 @40 A9';
>
> VOUCHER_RECORD:
>
> while ( my $record =  ) {
>
>my ( $important_num, $date_string )
>= unpack $EXTRACTION_LAYOUT, $record;
>
>next VOUCHER_RECORD if $important_num != 2;
>
>my $static_date = DateTime->new(
>year => 2009,
>    month => 3,
>day => 31
>);
>
>
># turn the extracted date string into a DateTime object
>
>my $date_formatter
>= new DateTime::Format::Strptime( pattern => '%d-%b-%y' );
>
>my $voucher_date
>= $date_formatter->parse_datetime($date_string);
>
>
># compare the DateTime compiled dates
>
>if ( DateTime->compare( $static_date, $voucher_date )) {
>
>print "Voucher ${voucher_date} is prior to ${static_date}" .
>  " and the important number is 2\n";
>}
> }
>
> __DATA__
>
> 60020003076570*,2,*20-SEP-08.01:09:18,,*04-NOV-08*,1,INR,,VOUCHER_BATCH_20080919_00014,2C,,0
>
> 326495*,5,*20-SEP-08.01:09:57,,*31-DEC-09*,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
>
> 327480,*2,*20-SEP-08.01:09:57,,*31-DEC-08*,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
>
> Steve
>


Re: script to compare dates

2009-08-18 Thread Telemachus
On Tue Aug 18 2009 @  7:55, Mihir Kamdar wrote:
> I dont have Datetime module installed. Is there a way without using
> DateTime??
I don't want to be glib, but I can see at least two broad possible options:

(1) Install DateTime (it's very worth it).
(2) Rewrite all the relevant code from DateTime (it's very not worth it,
except perhaps as a learning exercise or masochism).

More seriously getting date arithmetic right can be very hard. Your
particular need doesn't sound too complicated now (compare two dates to a
fixed date), but I still wouldn't choose to recreate a solution for date
parsing and comparison when there are good solutions easily available at
CPAN.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: script to compare dates

2009-08-18 Thread Steve Bertrand
Mihir Kamdar wrote:
> I dont have Datetime module installed. Is there a way without using
> DateTime??

As always, TIMTOWTDI, but I have to maintain a lot of legacy code, where
the original author (including myself) would rewrite date routines
(differently) in each subroutine that needed to parse/manipulate dates.

I would highly advise that you get DateTime installed at any cost. It is
consistent, extremely flexible, and very well maintained and documented.
 There is also a spectacular number of different formatting modules as
well that make all tasks involving dates easy and enjoyable.

Steve


smime.p7s
Description: S/MIME Cryptographic Signature


Re: script to compare dates

2009-08-18 Thread Shawn H. Corey

Steve Bertrand wrote:

Mihir Kamdar wrote:

I dont have Datetime module installed. Is there a way without using
DateTime??


As always, TIMTOWTDI, but I have to maintain a lot of legacy code, where
the original author (including myself) would rewrite date routines
(differently) in each subroutine that needed to parse/manipulate dates.

I would highly advise that you get DateTime installed at any cost. It is
consistent, extremely flexible, and very well maintained and documented.
 There is also a spectacular number of different formatting modules as
well that make all tasks involving dates easy and enjoyable.


Or even better, get the date format changed to Système International 
(SI), which is, 4-digit year, 2-digit month, 2-digit day.  I thought 
everyone fixed this problem in Y2K.



--
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: script to compare dates

2009-08-18 Thread Wagner, David --- Senior Programmer Analyst --- CFS
> -Original Message-
> From: Mihir Kamdar [mailto:kamdarmihi...@gmail.com] 
> Sent: Tuesday, August 18, 2009 08:55
> To: Steve Bertrand
> Cc: beginners
> Subject: Re: script to compare dates
> 
> I dont have Datetime module installed. Is there a way without using
> DateTime??
> 
You don't need it. You can with a little work generate what you
need. I don't have access to an open setup, so here is a shot at using
what you already have in a normal load. You will need to modify and
possibly add some checks, but all doable using std libs:

#!/usr/bin/perl

use strict;
use warnings;

use Time::Local 'timelocal';

my %MonthNameToNbr = qw( JAN 0 FEB 1 MAR 2 APR 3 MAY 4 JUN 5 JUL 6
AUG 7 SEP 8 OCT 9 NOV 10 DEC 11);

my $checkdateinsecs = timelocal(0, 0, 0, 31,
$MonthNameToNbr{q[mar]}, 109);   # generate check date once

printf "checkdateinsecs: %d\n",
$checkdateinsecs;
my $day;
my $month;
my $year;
my @cdr = ();

while (  ) {
chomp;
next if ( /^\s*$/ );
@cdr = split(/\s*,\s*/, $_);

if ( $cdr[0] !~ /^.(\d+)\S(\S{3})\S(\d+)/ ) {
 #print some type of error and either continue or die
 printf "(%5d)in error:\n<%s>\n",
$.,
$_;
 next;
 }
$day   = $1;
$month = uc($2);
$year  = $3;
my $dateinsecs = timelocal(0, 0, 0, $day,
$MonthNameToNbr{$month}, $year+100);

next if ( ! ( ($dateinsecs > $checkdateinsecs ) and
$cdr[1] =~ /2.*/
)
 );
# do your other processing
printf "dateinsecs: %d was greater (%d)\n",
$dateinsecs,
$.;
 }
__DATA__
*04-NOV-08*,2
*04-apr-09*,3
*xx-dec-08*,2
*04-apr-09*,2

Output:
[C:/CurrWrka/00Commonprlprod/src] aapl013s
checkdateinsecs: 1233385200
(3)in error:
<*xx-dec-08*,2>
dateinsecs: 1238824800 was greater (4)


> On Tue, Aug 18, 2009 at 7:37 AM, Steve Bertrand 
>  wrote:
> 
> >  Mihir Kamdar wrote:
> > > Hi,
> > >
> > > I want to write a script whose input data would be a csv 
> file and records
> > > would be as follows:-
> > >
> > > 60020003076570*,2,*20-SEP-08.01:09:18,,*04-NOV-08*
> > > ,1,INR,,VOUCHER_BATCH_20080919_00014,2C,,0
> > > 326495*,5,*20-SEP-08.01:09:57,,*31-DEC-09*
> > > ,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
> > > 327480,*2,*20-SEP-08.01:09:57,,*31-DEC-08*
> > > ,10,INR,,VOUCHER_BATCH_20080919_00024,1K,,0
> > >
> > > Here I want to compare whether the 5th field, which is 
> the date field
> > > is *earlier
> > > than 31-Mar-09 and 2nd field value is 2.*
> > >
> > > If yes, then I will take that record and store it in another file.
> > >
> > > Please help me as to how do I compare dates, preferably 
> with some sample
> > > code.
> > >
> > > I started coding for this as below, but am stuck on how 
> to compare date
> > in
> > > my input with another date.
> > >
> > > #!/usr/bin/perl
> > > use strict;
> > > use warnings ;
> > >
> > > open (my $IN_FILE,"<","testdata.txt") or die $!." file 
> not found" ;
> > > while (my $line=readline($IN_FILE))
> > > {
> > > my @cdr=split (/,/, $line) ;
> > > if($cdr[5]
> > > .
> > > .
> > > }
> >
> > For fun, and to try out a few things I came across in 
> Damian's book. I
> > use DateTime to manage all aspects of dates and times. The 
> code below
> > assumes that all records will always be in the exact same format.
> > Criticism welcome:
> >
> >
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> >
> > use DateTime::Format::Strptime;
> >
> > my $EXTRACTION_LAYOUT = '@16 A1 @40 A9';
> >
> > VOUCHER_RECORD:
> >
> > while ( my $record =  ) {
> >
> >my ( $important_num, $date_string )
> >= unpack $EXTRACTION_LAYOUT, $record;
> >
> >next VOUCHER_RECORD if $important_num != 2;
> >
> >my $static_date = DateTime->new(
> >year => 2009,
> >month => 3,
> >day => 31
> >);
> >
> >
> ># turn the extracted date str

Re: script to compare dates

2009-08-18 Thread Mihir Kamdar
thanks all.and how will be the code like for my requirement if i use
DateTime...

On Tue, Aug 18, 2009 at 10:09 AM, Shawn H. Corey wrote:

>  Steve Bertrand wrote:
>
>> Mihir Kamdar wrote:
>>
>>> I dont have Datetime module installed. Is there a way without using
>>> DateTime??
>>>
>>
>> As always, TIMTOWTDI, but I have to maintain a lot of legacy code, where
>> the original author (including myself) would rewrite date routines
>> (differently) in each subroutine that needed to parse/manipulate dates.
>>
>> I would highly advise that you get DateTime installed at any cost. It is
>> consistent, extremely flexible, and very well maintained and documented.
>>  There is also a spectacular number of different formatting modules as
>> well that make all tasks involving dates easy and enjoyable.
>>
>
> Or even better, get the date format changed to Système International (SI),
> which is, 4-digit year, 2-digit month, 2-digit day.  I thought everyone
> fixed this problem in Y2K.
>
>
> --
> Just my 0.0002 million dollars worth,
>  Shawn
>
> Programming is as much about organization and communication
> as it is about coding.
>
> I like Perl; it's the only language where you can bless your
> thingy.
>


Re: script to compare dates

2009-08-18 Thread Steve Bertrand
Mihir Kamdar wrote:
> thanks all.and how will be the code like for my requirement if i use
> DateTime...

I truly thought that you might have attempted to try the complete
cut/paste-able program I wrote and made slight changes to fit your
"requirement". Even if not, at least testing it would have been nice.

The code I gave you earlier is put verbatim below, with additional
functions.



#!/usr/bin/perl

use strict;
use warnings;

use DateTime::Format::Strptime;

my $EXTRACTION_LAYOUT = '@16 A1 @40 A9';

VOUCHER_RECORD:

while ( my $record =  ) {

my ( $important_num, $date_string )
= unpack $EXTRACTION_LAYOUT, $record;

next VOUCHER_RECORD if $important_num != 2;

my $static_date = DateTime->new(
year => 2009,
month => 3,
day => 31
);


# turn the extracted date string into a DateTime object

my $date_formatter
= new DateTime::Format::Strptime( pattern => '%d-%b-%y' );

my $voucher_date
= $date_formatter->parse_datetime($date_string);


# compare the DateTime compiled dates

if ( DateTime->compare( $static_date, $voucher_date )) {

# - put your record/store functions code in this space.
# - depending on what you want to do, these comments
#   are within the code block that ensures that your 2nd
#   field is equal to '2', and that the 5th field is less
#   than Mar 31, 2009

# - depending on how you want to "store" the information,
#   I might suggest http://perldoc.perl.org/Storable.html
}
}

__END__

Please at least copy/paste my code and try it if you've been able to
install DateTime. Use the example in my earlier post, as it also
contains the data which is properly formatted.

To be bluntly honest, I'm quite proud of my tiny code snip. I had to
research/try the patterns for DateTime to get them right, and counted
with my finger to position the layout properly.

...I am completely flabbergasted with your response.

See kids, the post I am responding to is not proper list etiquette!

Steve


smime.p7s
Description: S/MIME Cryptographic Signature


Re: script to compare dates

2009-08-18 Thread Mihir Kamdar
i am sorry Steve...actually I miswrote DateTime instead of DateManip...

i saw your code using DateTime but I before I posted this, I was trying
using DateManip...but while testing the code, I found out that DateManip is
not installed...

i tried executing your code as well but even DateTime is not installed in my
Linux box..

while trying to install both DateTime and DateManip in my machine, it is
giving some network error..."Url not found..."

need to figure out a way to install them..

On Tue, Aug 18, 2009 at 11:22 PM, Steve Bertrand  wrote:

> Mihir Kamdar wrote:
> > thanks all.and how will be the code like for my requirement if i use
> > DateTime...
>
> I truly thought that you might have attempted to try the complete
> cut/paste-able program I wrote and made slight changes to fit your
> "requirement". Even if not, at least testing it would have been nice.
>
> The code I gave you earlier is put verbatim below, with additional
> functions.
>
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use DateTime::Format::Strptime;
>
> my $EXTRACTION_LAYOUT = '@16 A1 @40 A9';
>
> VOUCHER_RECORD:
>
> while ( my $record =  ) {
>
>my ( $important_num, $date_string )
>= unpack $EXTRACTION_LAYOUT, $record;
>
>next VOUCHER_RECORD if $important_num != 2;
>
>my $static_date = DateTime->new(
>year => 2009,
>month => 3,
>day => 31
>);
>
>
># turn the extracted date string into a DateTime object
>
>my $date_formatter
>= new DateTime::Format::Strptime( pattern => '%d-%b-%y' );
>
>my $voucher_date
>= $date_formatter->parse_datetime($date_string);
>
>
># compare the DateTime compiled dates
>
>if ( DateTime->compare( $static_date, $voucher_date )) {
>
># - put your record/store functions code in this space.
># - depending on what you want to do, these comments
>#   are within the code block that ensures that your 2nd
>#   field is equal to '2', and that the 5th field is less
>#   than Mar 31, 2009
>
># - depending on how you want to "store" the information,
>#   I might suggest http://perldoc.perl.org/Storable.html
>}
> }
>
> __END__
>
> Please at least copy/paste my code and try it if you've been able to
> install DateTime. Use the example in my earlier post, as it also
> contains the data which is properly formatted.
>
> To be bluntly honest, I'm quite proud of my tiny code snip. I had to
> research/try the patterns for DateTime to get them right, and counted
> with my finger to position the layout properly.
>
> ...I am completely flabbergasted with your response.
>
> See kids, the post I am responding to is not proper list etiquette!
>
> Steve
>


Re: script to compare dates

2009-08-18 Thread Steve Bertrand
Mihir Kamdar wrote:
> i am sorry Steve...actually I miswrote DateTime instead of DateManip...
>  
> i saw your code using DateTime but I before I posted this, I was trying
> using DateManip...but while testing the code, I found out that DateManip
> is not installed...
>  
> i tried executing your code as well but even DateTime is not installed
> in my Linux box..
>  
> while trying to install both DateTime and DateManip in my machine, it is
> giving some network error..."Url not found..."
>  
> need to figure out a way to install them..

I'll be at the office for a little while longer. I'd be pleased to help
you out to get the modules installed, and help you on your way if I can.

Contact me off-list.

Steve


smime.p7s
Description: S/MIME Cryptographic Signature


Arrays, Dates, Indexing and Initialisation

2009-09-28 Thread Soham Das
Hello All,

I wanted some guidance with these questions of mine:

a.. How do I initialise an array of a definite size with zero. Say the C 
equivalent of such a statement will be:
  
   int a[125];
   for(i=0;i<125;i++) 
   a[i]=0;

b. Is it possible, to have dates as index? I am trying to parse and process 
data corresponding to a list of "trades" I have made(financial trades) and want 
to see, how my portfolio varies with time. So is it possible to do in such a 
way?



Hoping for some insights,

Soham

P.S: Would like to come in touch, with any Perl coder who engages in mechanical 
trading as well. Always good to find folks with whom you can bounce off ideas.

Soham



  Yahoo! India has a new look. Take a sneak peek http://in.yahoo.com/trynew


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Help with hash of dates

2005-08-08 Thread Kevin Old
Hello everyone,

I'm trying to come up with a way to automatically create a hash like
the following:

use Tie::IxHash;
tie my %pairs, "Tie::IxHash";

%pairs = (
  '1' => {
 'start' => '04/24/05',
 'end' => '04/30/05'
   },
  '2' => {
 'start' => '05/01/05',
 'end' => '05/07/05'
   },
  '3' => {
 'start' => '05/08/05',
 'end' => '05/14/05'
   },
);

It's a hash with the start and end date for each week with the start
date being Sunday and the end date being the following Saturday.

I know all about Data::Calc, Date::Manip and have scoured them for
every possible way of coming up with something like this, but I can't
seem to get it.

Ultimately, if I could find a solution that would give me dates like
these for any day range (for example Tues - Mon) and a start and end
date and it fill in the blanks that would be great.

I've even tried working with the Date::Manip ParseRecur function and
can't seem to get anything to work.

Any help is greatly appreciated!

Kevin
-- 
Kevin Old
[EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Date::Parse and strange dates

2014-07-25 Thread Chris Knipe
Hi All,

 

I have the odd (very rare) case where I am given a date in an incorrect
format.  I already use Date::Parse to convert the dates to a unix timestamp,
and it's working incredibly well.  However, on the rare case that I get
incorrect dates, Date::Parse does not like them either and errors out.  The
formats in question that I can't parse basically looks like

 

Thu, 23 Oct 2008 12:06:48+0400

 

Note the lack of a space between the seconds and the timezone.

 

Is there a simple quick way to fix that by means of a regex?

 

Many thanks,

Chris.

 



Range of dates help needed

2003-10-29 Thread Kevin Old
Hello everyone,

I have a subroutine below that uses Date::Manip to build a hash with
keys of the previous Wednesday to the next Tuesday range from the
beginning of the year until today.  For instance:

%pairs = (
#didn't want to list the whole year, but you get the point
'10/15/2003' => '10/21/2003',
'10/22/2003' => '10/28/2003',
);

Here's my subroutine:

sub wedToTues() {
my ($day, $month, $year) = (localtime)[3,4,5];
$year += 1900;
$month++;
my $beginyear = &ParseDate("$year/01/01");
my $today = &ParseDate("today");
my $firsttues = &ParseDate("$year/01/07");
my $endyear = &ParseDate("$year/12/31");

    #print "$beginyear $endyear\n";

#Build an array of every Tuesday in the current year
my @dates =
&ParseRecur("0:0:1*2:0:0:0",$firsttues,$beginyear,$today);

use Tie::IxHash;
tie my %pairs, "Tie::IxHash";

foreach my $date (@dates) {

my $lastWed = &DateCalc("$date","- 6 days");

#my $ulastWed = &UnixDate($lastWed, "%Y%m%d");
#my $udate = &UnixDate($date, "%Y%m%d");
my $ulastWed = &UnixDate($lastWed, "%m/%d/%Y");
my $udate = &UnixDate($date, "%m/%d/%Y");
$pairs{$ulastWed} = $udate;
}

return \%pairs;
}

Yes, I understand that to adjust the variables that I pass to
ParseRecur, but I'm not sure how to go about doing what I need.

I'll try to explain as best as I can.  First, I'll be changing this
subroutine to be Saturdays to Fridays rather than Wednesdays to
Tuesdays.  Then based on the day it's run, I need to only get the
previous 3 weeks and the next 4 weeks.

Basically I'd like a hash (or whatever) that looks like this:

%datepairs = (
# Saturday to  Following Friday
'10/11/2003' => '10/17/2003',
'10/18/2003' => '10/24/2003',
'10/25/2003' => '10/31/2003',
'11/01/2003' => '11/07/2003',
'11/08/2003' => '11/14/2003',
'11/15/2003' => '11/21/2003',
'11/22/2003' => '11/28/2003',
);


Can anyone offer suggestions or a more graceful way of doing this?

Thanks,
Kevin

-- 
Kevin Old <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Comparing Dates Conditional statements

2003-05-27 Thread Mark G
> How can I have condition as such
> 
> $date = 'XX/XX/XX'; <-insert any date
> If $date is greater then 01/01/02 then do .
> Else 
> 

here is one simple way:

<~~~cut

$foo="01/01/02";
$bar="01/03/02";

$foo =~ s/\///g;
$bar =~ s/\///g;


if( $foo > $bar ){

 print "\$foo is greater then \$bar \n";

}
elsif( $foo == $bar){

 print "\$foo is equal to \$bar \n"; 

}
else {
 
 print "\$bar is greater then \$foo \n";

}

<~~paste
- Original Message - 
From: "Paul Kraus" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 27, 2003 3:43 PM
Subject: Comparing Dates Conditional statements


> How can I have condition as such
> 
> $date = 'XX/XX/XX'; <-insert any date
> If $date is greater then 01/01/02 then do .
> Else 
> 
> 
> Paul
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Comparing Dates Conditional statements

2003-05-27 Thread Tim Johnson

That won't work if the dates are more than a year apart(i.e. 100302 will
appear to be greater than 011503).  I would recommend looking into the
Time::Local module.  You can use it to convert the text dates into Perl
time() format.  Then you can easily do a numeric conversion.

-Original Message-
From: Mark G [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 27, 2003 2:04 PM
To: [EMAIL PROTECTED]
Cc: perl
Subject: Re: Comparing Dates Conditional statements


> How can I have condition as such
> 
> $date = 'XX/XX/XX'; <-insert any date
> If $date is greater then 01/01/02 then do .
> Else 
> 

here is one simple way:

<~~~cut

$foo="01/01/02";
$bar="01/03/02";

$foo =~ s/\///g;
$bar =~ s/\///g;


if( $foo > $bar ){

 print "\$foo is greater then \$bar \n";

}
elsif( $foo == $bar){

 print "\$foo is equal to \$bar \n"; 

}
else {
 
 print "\$bar is greater then \$foo \n";

}

<~~paste
- Original Message - 
From: "Paul Kraus" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 27, 2003 3:43 PM
Subject: Comparing Dates Conditional statements


> How can I have condition as such
> 
> $date = 'XX/XX/XX'; <-insert any date
> If $date is greater then 01/01/02 then do .
> Else 
> 
> 
> Paul
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Comparing Dates Conditional statements

2003-05-27 Thread Mark G
> That won't work if the dates are more than a year apart(i.e. >100302 will

Thanx Tim, I didnt think about that. Perhaps you will need to break up the
string into 3 fields.

Mark G
- Original Message - 
From: "Tim Johnson" <[EMAIL PROTECTED]>
To: "'Mark G'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Cc: "perl" <[EMAIL PROTECTED]>
Sent: Tuesday, May 27, 2003 5:10 PM
Subject: RE: Comparing Dates Conditional statements


>
> That won't work if the dates are more than a year apart(i.e. 100302 will
> appear to be greater than 011503).  I would recommend looking into the
> Time::Local module.  You can use it to convert the text dates into Perl
> time() format.  Then you can easily do a numeric conversion.
>
> -Original Message-
> From: Mark G [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, May 27, 2003 2:04 PM
> To: [EMAIL PROTECTED]
> Cc: perl
> Subject: Re: Comparing Dates Conditional statements
>
>
> > How can I have condition as such
> >
> > $date = 'XX/XX/XX'; <-insert any date
> > If $date is greater then 01/01/02 then do .
> > Else 
> >
>
> here is one simple way:
>
> <~~~cut
>
> $foo="01/01/02";
> $bar="01/03/02";
>
> $foo =~ s/\///g;
> $bar =~ s/\///g;
>
>
> if( $foo > $bar ){
>
>  print "\$foo is greater then \$bar \n";
>
> }
> elsif( $foo == $bar){
>
>  print "\$foo is equal to \$bar \n";
>
> }
> else {
>
>  print "\$bar is greater then \$foo \n";
>
> }
>
> <~~paste
> - Original Message - 
> From: "Paul Kraus" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, May 27, 2003 3:43 PM
> Subject: Comparing Dates Conditional statements
>
>
> > How can I have condition as such
> >
> > $date = 'XX/XX/XX'; <-insert any date
> > If $date is greater then 01/01/02 then do .
> > Else 
> >
> >
> > Paul
> >
> >
> > -- 
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Comparing Dates Conditional statements

2003-05-27 Thread Dan Muey
While using a module or a database's built in time/date functions 
would be best you can do it as a straight numeric comparison.
But you must be very careful as to how you order those numbers or you'll get
Improper results.

# mmdd
$foo = 20030101;
$bar = 20021231;
# can even add hours minutes seconds but I'll leave that as an
# Exercise in logic :)

if( $foo > $bar ){ print "\$foo is greater then \$bar \n"; }
elsif( $foo == $bar){  print "\$foo is equal to \$bar \n"; }
else { print "\$bar is greater then \$foo \n"; }

HTH

DMuey


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: regex question matching dates

2008-05-28 Thread John W. Krahn

Richard Lee wrote:

given then ARGV[0] is 2008052803, why woulnd't below regex match them??


2008052803 is a ten digit number.



} elsif ( $ARGV[0] =~ m/\b2008[01][1-31]([01][0-9]|2[0-3])\b/ ) {


Your pattern matches eight digits with a \b word boundary at each end so 
it will never match a ten digit number.  Also the character class [1-31] 
could be more simply written as [1-3] (repeated characters are ignored.)




 @array = qx#ls -tr $directory/$ARGV[0]*#;


Why not do that directly in perl:

 @array = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M ], 
glob "$directory/$ARGV[0]*";




 #2008052803



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: regex question matching dates

2008-05-28 Thread John W. Krahn

John W. Krahn wrote:

Richard Lee wrote:


 @array = qx#ls -tr $directory/$ARGV[0]*#;


Why not do that directly in perl:

 @array = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M ], 
glob "$directory/$ARGV[0]*";


Sorry, that should be:

 @array = map $_->[0], sort { $b->[1] <=> $a->[1] } map [ $_, -M ], 
glob "$directory/$ARGV[0]*";




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: regex question matching dates

2008-05-28 Thread Richard Lee

John W. Krahn wrote:

Richard Lee wrote:

given then ARGV[0] is 2008052803, why woulnd't below regex match them??


2008052803 is a ten digit number.



} elsif ( $ARGV[0] =~ m/\b2008[01][1-31]([01][0-9]|2[0-3])\b/ ) {


Your pattern matches eight digits with a \b word boundary at each end 
so it will never match a ten digit number.  Also the character class 
[1-31] could be more simply written as [1-3] (repeated characters are 
ignored.)




 @array = qx#ls -tr $directory/$ARGV[0]*#;


Why not do that directly in perl:

 @array = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M 
], glob "$directory/$ARGV[0]*";




 #2008052803



John

hey thanks!

this works fine now

} elsif ( $ARGV[0] =~ 
m/\b2008(0[1-9]|1[12])(0[1-9]|1[0-9]|2[0-9]|3[01])([01][0-9]|2[0-3])\b/ ) {

 @array = qx#ls -tr $directory/$ARGV[0]*#;
 #2008052803
} else {

I will try that direct perl solution as well!!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: regex question matching dates

2008-05-28 Thread John W. Krahn

Richard Lee wrote:

John W. Krahn wrote:

Richard Lee wrote:

given then ARGV[0] is 2008052803, why woulnd't below regex match them??


2008052803 is a ten digit number.



} elsif ( $ARGV[0] =~ m/\b2008[01][1-31]([01][0-9]|2[0-3])\b/ ) {


Your pattern matches eight digits with a \b word boundary at each end 
so it will never match a ten digit number.  Also the character class 
[1-31] could be more simply written as [1-3] (repeated characters are 
ignored.)




 @array = qx#ls -tr $directory/$ARGV[0]*#;


Why not do that directly in perl:

 @array = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M 
], glob "$directory/$ARGV[0]*";


hey thanks!

this works fine now

} elsif ( $ARGV[0] =~ 
m/\b2008(0[1-9]|1[12])(0[1-9]|1[0-9]|2[0-9]|3[01])([01][0-9]|2[0-3])\b/ ) {

  ^
So you don't want to test for October?



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: regex question matching dates

2008-05-29 Thread Richard Lee

John W. Krahn wrote:



} elsif ( $ARGV[0] =~ 
m/\b2008(0[1-9]|1[12])(0[1-9]|1[0-9]|2[0-9]|3[01])([01][0-9]|2[0-3])\b/ 
) {

  ^
So you don't want to test for October?



John

fixed now. thanks!!

} elsif ( $ARGV[0] =~ 
m/\b2008(0[1-9]|1[012])(0[1-9]|1[0-9]|2[0-9]|3[01])([01][0-9]|2[0-3])\b/ ) {

 @array = qx#ls -tr $directory/$ARGV[0]*#;
 $hour = substr($ARGV[0], 8 , 2);
 $date_1 = substr($ARGV[0], 4 , 4);

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




how to produce random dates

2008-09-20 Thread itshardtogetone
Hi,
How do I randomly produce a date between 1st Jan 1960 to 31th December 1985. It 
must be able to show the day month year.
I only know how to produce a random number between 1960 to 1985 using rand like 
this :

my $year = int (rand 26) + 1960;

Thanks

Re: Dates are killing me..

2004-07-07 Thread Johan Viklund
Hi

Use the following methods from the Date::Calc module from CPAN:

Week_of_Year:   
($week,$year) = Week_of_Year($year,$month,$day);

Monday_of_Week: 
($year,$month,$day) = Monday_of_Week($week,$year);

Add_Delta_Days: 
($year,$month,$day) = Add_Delta_Days($year,$month,$day, $Dd);

Shouldn't be too hard I think.

ons 2004-07-07 klockan 06.03 skrev Chris Puccio:
> Hi Guys,
> 
> I'm having a real hard time trying to figure this out..
> 
> There are tons of modules on dates, etc, but I can't seem to find one to do 
> what I need.
> 
> I have one date, for example: 2004-07-07.
> 
> I need to take that date, get Monday's date and Sunday's date where 2004-07-07 
> is between.
> 
> Any suggestions?
> 
> Thanks!!
> -c
-- 
Johan Viklund <[EMAIL PROTECTED]>


signature.asc
Description: Detta =?ISO-8859-1?Q?=E4r?= en digitalt signerad	meddelandedel


RE: Dates are killing me..

2004-07-07 Thread Bakken, Luke
> Hi Guys,
> 
> I'm having a real hard time trying to figure this out..
> 
> There are tons of modules on dates, etc, but I can't seem to 
> find one to do 
> what I need.
> 
> I have one date, for example: 2004-07-07.
> 
> I need to take that date, get Monday's date and Sunday's date 
> where 2004-07-07 
> is between.
> 
> Any suggestions?
> 
> Thanks!!
> -c

This was a fun little problem!

No special modules are needed. I believe POSIX and Time::Local should be
in every distribution. I tested this with ActivePerl 5.8.3 on Win32.

use strict;
use warnings;
use Time::Local qw(timelocal);
use POSIX qw(strftime);

unless ($ARGV[0] =~ /^\d{4}-\d{2}-\d{2}$/) {
die "Date given must be in -MM-DD form.\n";
}
my @given_date = split /-/, $ARGV[0];
my $given_year = shift @given_date;
# Months start at zero
my $given_month = shift @given_date;
--$given_month;
my $given_day = shift @given_date;

# We want these dates
# Monday ... Given Date ... Sunday
# ^^^^
#   1   X 0(7)
my $given_time = timelocal(0, 0, 0, $given_day, $given_month,
$given_year);

# Get the day of week of given date.
# 0 is Sunday, 1 is Monday, 6 is Saturday
my $wday = (localtime($given_time))[6];

my $days_to_prev_monday;
my $days_to_next_sunday;
if ($wday == 0) {
# Given date is a Sunday
# Next Sunday is 7 days from now
# Previous Monday is six days ago
$days_to_prev_monday = 6;
$days_to_next_sunday = 7;
} elsif ($wday == 1) {
# Given date is a Monday
# Previous Monday is 7 days ago
# Next Sunday is six days from now
$days_to_prev_monday = 7;
$days_to_next_sunday = 6;
} else {
# Date given is between a Monday and a Sunday
$days_to_prev_monday = $wday - 1;
$days_to_next_sunday = 7 - $wday;
}
# Time returned from timelocal is in seconds, time given to
# localtime is in seconds as well. 86400 seconds in a day.
my @prev_mon_date = localtime($given_time - ($days_to_prev_monday *
86400));
my @next_sun_date = localtime($given_time + ($days_to_next_sunday *
86400));
my $previous_monday = strftime '%Y-%m-%d', @prev_mon_date;
my $next_sunday = strftime '%Y-%m-%d', @next_sun_date;

print "Previous Monday: $previous_monday\n";
print "Given Date:  $ARGV[0]\n";
print "Next Sunday: $next_sunday\n";

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Dates are killing me..

2004-07-07 Thread Chris Puccio
Luke,

Thanks!!! Works exactly as needed!
-c


On Wednesday 07 July 2004 09:41 am, Bakken, Luke wrote:
> > Hi Guys,
> >
> > I'm having a real hard time trying to figure this out..
> >
> > There are tons of modules on dates, etc, but I can't seem to
> > find one to do
> > what I need.
> >
> > I have one date, for example: 2004-07-07.
> >
> > I need to take that date, get Monday's date and Sunday's date
> > where 2004-07-07
> > is between.
> >
> > Any suggestions?
> >
> > Thanks!!
> > -c
>
> This was a fun little problem!
>
> No special modules are needed. I believe POSIX and Time::Local should be
> in every distribution. I tested this with ActivePerl 5.8.3 on Win32.
>
> use strict;
> use warnings;
> use Time::Local qw(timelocal);
> use POSIX qw(strftime);
>
> unless ($ARGV[0] =~ /^\d{4}-\d{2}-\d{2}$/) {
>   die "Date given must be in -MM-DD form.\n";
> }
> my @given_date = split /-/, $ARGV[0];
> my $given_year = shift @given_date;
> # Months start at zero
> my $given_month = shift @given_date;
> --$given_month;
> my $given_day = shift @given_date;
>
> # We want these dates
> # Monday ... Given Date ... Sunday
> # ^^^^
> #   1   X 0(7)
> my $given_time = timelocal(0, 0, 0, $given_day, $given_month,
> $given_year);
>
> # Get the day of week of given date.
> # 0 is Sunday, 1 is Monday, 6 is Saturday
> my $wday = (localtime($given_time))[6];
>
> my $days_to_prev_monday;
> my $days_to_next_sunday;
> if ($wday == 0) {
>   # Given date is a Sunday
>   # Next Sunday is 7 days from now
>   # Previous Monday is six days ago
>   $days_to_prev_monday = 6;
>   $days_to_next_sunday = 7;
> } elsif ($wday == 1) {
>   # Given date is a Monday
>   # Previous Monday is 7 days ago
>   # Next Sunday is six days from now
>   $days_to_prev_monday = 7;
>   $days_to_next_sunday = 6;
> } else {
>   # Date given is between a Monday and a Sunday
>   $days_to_prev_monday = $wday - 1;
>   $days_to_next_sunday = 7 - $wday;
> }
> # Time returned from timelocal is in seconds, time given to
> # localtime is in seconds as well. 86400 seconds in a day.
> my @prev_mon_date = localtime($given_time - ($days_to_prev_monday *
> 86400));
> my @next_sun_date = localtime($given_time + ($days_to_next_sunday *
> 86400));
> my $previous_monday = strftime '%Y-%m-%d', @prev_mon_date;
> my $next_sunday = strftime '%Y-%m-%d', @next_sun_date;
>
> print "Previous Monday: $previous_monday\n";
> print "Given Date:  $ARGV[0]\n";
> print "Next Sunday: $next_sunday\n";


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Dates are killing me..

2004-07-07 Thread Chris Charley
Like Luke's solution, but using Date::Simple which comes with the standard
distro of Perl.

#!/usr/bin/perl
use strict;
use warnings;
use Date::Calc qw/ Day_of_Week Add_Delta_Days /;

my @days = (undef, qw/ Mon Tue Wed Thur Fri Sat Sun /);

if ($ARGV[0] !~ /^\d{4}-\d{2}-\d{2}$/) {
 die "Date given must be in -MM-DD form.\n";
}

my @ymd = split /-/, $ARGV[0]; # year,month,day
my $dow = Day_of_Week @ymd;

my $mon = sprintf "%s-%02s-%02s", Add_Delta_Days @ymd, 1 -($dow==1 ?
8:$dow);
my $sun = sprintf "%s-%02s-%02s", Add_Delta_Days @ymd, 7 -($dow==7 ?
0:$dow);

print "Previous Monday: $mon\n";
print "Given Date:  $ARGV[0] $days[$dow]\n";
print "Next Sunday: $sun\n";

Chris



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




  1   2   >