CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
yday

 



ima
Deleted

Apr 14, 2000, 3:23 AM

Post #1 of 5 (984 views)
yday Can't Post

I need some assistance in getting the day number of an inputted date.

Basically, u suer will fill in a date on a website then click submit. I then need to find out what the day number of the year this is (yday) - anyone???

Thanks in advance,
Wayne


japhy
Enthusiast

Apr 14, 2000, 3:27 AM

Post #2 of 5 (984 views)
Re: yday [In reply to] Can't Post

This is part of the builtin localtime() function in Perl. From the Perl documentation for localtime():

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
</pre><HR></BLOCKQUOTE>

So you want to do something like:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$day_of_year = (localtime)[7];
</pre><HR></BLOCKQUOTE>

[This message has been edited by japhy (edited 04-14-2000).]


ima
Deleted

Apr 14, 2000, 3:31 AM

Post #3 of 5 (984 views)
Re: yday [In reply to] Can't Post

But how does this find the day number of the date the user chooses on the form?

I can get the current date information but not the yday of a date entered by a user


japhy
Enthusiast

Apr 14, 2000, 4:41 AM

Post #4 of 5 (984 views)
Re: yday [In reply to] Can't Post

I'm sorry, I misinterpreted the question. Well, you need to know what format they're entering the date in. After you've gotten into a workable format, I'd use the standard distribution Time::Local module.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use Time::Local;
$time = timelocal($s,$m,$h,$day,$mon,$yr);
$yday = (localtime($time))[7];
</pre><HR></BLOCKQUOTE>

The values for timelocal()'s arguments must be in the same format as localtime() returns. That means seconds are 0 -> 59, minutes are 0 -> 59, hours are 0 -> 23, day is 1 -> 31, month is 0 -> 11, and year is the current year - 1900. Example call:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use Time::Local;
# the stroke of midnight on my birthday
$time = timelocal(0,0,0,9,11,81);
$yday = (localtime($time))[7];

print "I was born on day $yday of the year.";
</pre><HR></BLOCKQUOTE>


ima
Deleted

Apr 14, 2000, 4:47 AM

Post #5 of 5 (984 views)
Re: yday [In reply to] Can't Post

Thanks - it works great.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives