DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 31st August 2009
cksraj cksraj is offline
Real Name: Crew Kasy Raj
Port Guard
 
Join Date: Mar 2009
Posts: 12
Thanked 0 Times in 0 Posts
Unhappy Get the Days of the Week

Hi All

I would like to get the days of the week. I could able to find the no of weeks for the month. But I want to list the days of the perticular week in drop down.

For examble;(year is 2009)

if I say First week of August
then days of the week = 'Saturday'.
if I say Second week of August
then days of the week = 'Sunday','Monday','Tuesday','Wednesday','Thursday' ,'Friday','Saturday'.
...

if I say Sixth week of August
then days of the week = 'Sunday','Monday'.

Anybody can help me in this?

Thanks
Crew Kasy Raj
Reply With Quote
  #2   (View Single Post)  
Old 31st August 2009
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Thanked 49 Times in 43 Posts
Default

Code:
cal aug 2009 | perl -nae '$w=$weeknum=1; @d=split if $.==2;if($.==$w+2){for(0..6){if(defined($F[$_])){$_-=@F if $w==1;print "$d[$_] "}};print "\n" if @F!=0}'
Set the variable $weeknum (1-6) as required.
Reply With Quote
  #3   (View Single Post)  
Old 25th September 2009
Business_woman's Avatar
Business_woman Business_woman is offline
lieutenant
 
Join Date: May 2008
Posts: 45
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by ephemera View Post
Code:
cal aug 2009 | perl -nae '$w=$weeknum=1; @d=split if $.==2;if($.==$w+2){for(0..6){if(defined($F[$_])){$_-=@F if $w==1;print "$d[$_] "}};print "\n" if @F!=0}'
Set the variable $weeknum (1-6) as required.
Seriously?
__________________
I like cookies...
Reply With Quote
  #4   (View Single Post)  
Old 26th September 2009
robbak's Avatar
robbak robbak is offline
Real Name: Robert Backhaus
VPN Cryptographer
 
Join Date: May 2008
Location: North Queensland, Australia
Posts: 366
Thanked 40 Times in 39 Posts
Default

What language? The example is pretty standard perl, although more readable if split onto more lines.

No elegant answer comes to mind, I'd have to say. We'd have to know your target language, so we could think of the standard date functions available, so we could think of a solution.

Notes: Weeks could be 1 to 6, by your definition. For weeks 1 to 5 ( or 4 in some cases!) this could be based on the n'th saturday. The kind of crocks that are half-forming in my mind are suggesting to me that this would be better not done: think up a different interface!

(Unless this is your homework, in which case the answer is to find out yourself.)
__________________
The only dumb question is a question not asked.
The only dumb answer is an answer not given.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
my X11 or Gnome kill after 5 days mfaridi FreeBSD General 14 13th November 2008 04:27 AM


All times are GMT. The time now is 01:40 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick