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]
 




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 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] 




**
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: 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: 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]
>>  
>> 
>> 
>> 
>
>
>
>
>
>This mail sent through www.mywaterloo.ca
>
>-- 
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
> 
>
>
>
>
>-- 
>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]
 




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 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]
>  
> 
> 
> 





This mail sent through www.mywaterloo.ca

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




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]
 




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]
 




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-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-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 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 are killing me..

2004-07-07 Thread Jeff 'japhy' Pinyan
On Jul 7, Chris Charley said:

>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 /;

This uses Date::Calc, not Date::Simple... and neither of those came with
*my* standard Perl installation.

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


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




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]
 




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]
 




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]
 




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 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]




RE: Dates in file or directory names ?

2002-02-18 Thread Dave Cross

On Sat, 02 Feb 2002 17:11:12 +, Timothy Johnson wrote:
 
> -Original Message-
> > From: Dave Cross
> > To: [EMAIL PROTECTED]
> > Sent: 2/2/02 1:01 AM
> > Subject: Re: Dates in file or directory names ?
> > 
> > On Thu, 31 Jan 2002 21:20:16 +, Mark Richmond wrote:
> > 
> >> Ok, so I'm confused
> >> What I want to do is create a directory where the name is the current
> >> date say mkdir(2002131)
> >> What Can't figure out is how to build the date string. I'm sure I'm
> >> just missing something.
> >> Any thoughts.
> > 
> > [can you please try to configure your mail client not to use HTML]
> > 
> > You probably need the "strftime" function from the POSIX module.
> > 
> > my $date = strftime('%Y%m%d', localtime);
>
> Or you can just use localtime();
> 
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); 
> my $date = ($year + 1900).($mon + 1).$mday;
> 
> mkdir($date);

Well perhaps. But that breaks when either $mon or $mday have only one
digit. At which point you'll need to wheel out something like "sprintf" -
so you may as well use "strftime" anyway :)

Dave...

-- 

  Drugs are just bad m'kay

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




RE: Dates in file or directory names ?

2002-02-02 Thread Timothy Johnson

 
Or you can just use localtime();

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
my $date = ($year + 1900).($mon + 1).$mday;

mkdir($date);

-Original Message-
From: Dave Cross
To: [EMAIL PROTECTED]
Sent: 2/2/02 1:01 AM
Subject: Re: Dates in file or directory names ?

On Thu, 31 Jan 2002 21:20:16 +, Mark Richmond wrote:

> Ok, so I'm confused
> What I want to do is create a directory where the name is the current
> date say mkdir(2002131)
> What Can't figure out is how to build the date string. I'm sure I'm
> just missing something.
> Any thoughts.

[can you please try to configure your mail client not to use HTML]

You probably need the "strftime" function from the POSIX module.

my $date = strftime('%Y%m%d', localtime);


hth,

Dave...

-- 

  "Don't you boys know any _nice_ songs?"

-- 
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: Dates in file or directory names ?

2002-02-02 Thread Dave Cross

On Thu, 31 Jan 2002 21:20:16 +, Mark Richmond wrote:

> Ok, so I'm confused
> What I want to do is create a directory where the name is the current
> date say mkdir(2002131)
> What Can't figure out is how to build the date string. I'm sure I'm
> just missing something.
> Any thoughts.

[can you please try to configure your mail client not to use HTML]

You probably need the "strftime" function from the POSIX module.

my $date = strftime('%Y%m%d', localtime);


hth,

Dave...

-- 

  "Don't you boys know any _nice_ songs?"

-- 
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: 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 in file or directory names ?

2002-01-31 Thread Wagner-David
Title: Blank



    use somehting 
like:

my ($mday, $mon, $year) = 
(localtime(time))[3..5];    
# pull day,month, year 
only$year += 1900; # 
want 4 digit date$mon++;   # 
need to add 1 to month(runs from 0 to 11)
my $MyDirectory = sprintf "%04d%02d%02d", $year, $mon, 
$mday
This will mmdd 
format.
Wags 
;)

  -Original Message-From: Mark Richmond 
  [mailto:[EMAIL PROTECTED]]Sent: Thursday, January 31, 
  2002 13:20To: [EMAIL PROTECTED]Subject: Dates in file 
  or directory names ?
  Ok, so I'm confused
   
  What I want to do is create a directory 
  where the name is the current date say 
  mkdir(2002131);  
  What Can't figure out is how to build the 
  date string. I'm sure I'm just missing something. 
  Any thoughts. 
   
      -regards 
      -mark 
  - Mark Richmond <[EMAIL PROTECTED]> Airvana Inc. 
  25 Industrial Ave. Chelmsford, MA 01824 Voice: 978-250-2669 
  Fax:   978-250-3910 
   

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


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]




RE: Dates subtraction - one more simplification

2001-07-22 Thread Steve Howard

Still using Date::Calc, here is a much easier way to do what I posted
earlier:

use Date::Calc qw(:all);


$dd = Delta_Days(Today(), 2002, 1, 23);

print "$dd\n";

In that case it is giving the difference between January 23, 2002 and today
in days. I had forgotten about the "Today" function when I wrote the earlier
one. There is a "Now" function that works like today except that is returns
hours minutes and seconds of the time, and a Today_and_Now function that
returns both.

Anyway, I thought I'd post the simpler way - so you don't have to do any
further manipulations of system dates to get there.

Steve H.

-Original Message-
From: Jeff 'japhy/Marillion' Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Sunday, July 22, 2001 9:37 AM
To: Steve Howard
Cc: Ackim Chisha; [EMAIL PROTECTED]
Subject: RE: Dates subtraction


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]


-- 
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: 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]