For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > Find first day of every week in a month









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Find first day of every week in a month
Anil Kumar

2005-08-29, 7:55 am


I am new to perl and working for a small project...

I need some help from you..

How to get all the first days of a w in a month.
John W. Krahn

2005-08-29, 7:55 am

Anil Kumar, Malyala wrote:
> I am new to perl and working for a small project...
>
> I need some help from you..
>
> How to get all the first days of a w in a month.


$ perl -le'
# get every Monday for August 2005
use Time::Local;
# start at noon August 1st
my $day = 1;
while ( eval { @date = gmtime( $date = timegm( 0, 0, 12, $day++, 7, 2005 ) ) } ) {
if ( $date[ 6 ] == 1 ) {
print scalar gmtime $date;
}
}
'
Mon Aug 1 12:00:00 2005
Mon Aug 8 12:00:00 2005
Mon Aug 15 12:00:00 2005
Mon Aug 22 12:00:00 2005
Mon Aug 29 12:00:00 2005



John
--
use Perl;
program
fulfillment
Owen Cook

2005-08-29, 7:55 am


On Mon, 29 Aug 2005, Anil Kumar, Malyala wrote:

>
> I am new to perl and working for a small project...
>
> I need some help from you..
>
> How to get all the first days of a w in a month.


There is a module Date::Calc and from that

Day_of_W

$dow = Day_of_W($year,$month,$day);

Here is a little program for you.

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

use Date::Calc qw(Day_of_W);
use strict;

my $dow = Day_of_W(2005,9,1);

print "$dow\n";
--------------------------------------------

The answer is 4. So now make an array or hash to convert the 4 to Thursday



Owen

Jeff 'japhy' Pinyan

2005-08-29, 9:55 pm

On Aug 29, Anil Kumar, Malyala said:

> How to get all the first days of a w in a month.


How do you define the "first day of a w"? Do you mean "I want to know
the dates of every Sunday in a month"? Please be specific.

--
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
Anil Kumar

2005-08-30, 3:55 am


Hi,

I want the first day of every w in a month...

Example consider Sep 2005

So I want=20
1 Sep 2005 (which is the first day of 1st w in Sep)
5 Sep 2005 (which is the first day of 2nd w in Sep)
12 Sep 2005 (first day of 3rd w in sep)
19 Sep 2005 (first day of 4th w in Sep)
26 Sep 2005 (first day of 5th w in Sep)

Anil

-----Original Message-----
From: Jeff 'japhy' Pinyan [mailto:japhy@perlmonk.org]=20
Sent: Monday, August 29, 2005 7:10 PM
To: Anil Kumar, Malyala
Cc: Beginners Perl
Subject: Re: Find first day of every w in a month

On Aug 29, Anil Kumar, Malyala said:

> How to get all the first days of a w in a month.


How do you define the "first day of a w"? Do you mean "I want to
know the dates of every Sunday in a month"? Please be specific.

--=20
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: beginners-unsubscribe@perl.org For additional
commands, e-mail: beginners-help@perl.org <http://learn.perl.org/>
<http://learn.perl.org/first-response>


Chris Devers

2005-08-30, 3:55 am

On Tue, 30 Aug 2005, Anil Kumar, Malyala wrote:

> I want the first day of every w in a month...
>
> Example consider Sep 2005
>
> So I want
> 1 Sep 2005 (which is the first day of 1st w in Sep)
> 5 Sep 2005 (which is the first day of 2nd w in Sep)
> 12 Sep 2005 (first day of 3rd w in sep)
> 19 Sep 2005 (first day of 4th w in Sep)
> 26 Sep 2005 (first day of 5th w in Sep)


Super.

What have you tried so far?

As usual, show us your code, and we can help fix it.

As usual, this isn't a script writing service.

We're here to help you learn how to write your own code.



--
Chris Devers
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com