Current location: Hot Scripts Forums » Programming Languages » PHP » Using number of the week


Using number of the week

Reply
  #1 (permalink)  
Old 10-19-04, 03:18 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Question Using number of the week

Hi kidz,

My problem

1.
How can I get a date (maybe the first day of that week) of the a selected week from the week number. i.e

If it's the week 42 of 2004 it should be the timestamp of 17th Oct 2004?

D
Reply With Quote
  #2 (permalink)  
Old 10-19-04, 09:58 AM
Wraith Wraith is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by dihan
Hi kidz,

My problem

1.
How can I get a date (maybe the first day of that week) of the a selected week from the week number. i.e

If it's the week 42 of 2004 it should be the timestamp of 17th Oct 2004?

D
The date is best shown using Unix EPoch. Check http://www.php.net/date for details.

-Wraith
Reply With Quote
  #3 (permalink)  
Old 10-22-04, 04:04 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down

I did have a look at that but I cannot figure it out.

It says when you convert the week number to a date it is normally gives the monday of that week. But what is the function/code to get that date?
Reply With Quote
  #4 (permalink)  
Old 10-27-04, 03:47 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
bump... anyone?
Reply With Quote
  #5 (permalink)  
Old 10-27-04, 04:37 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
this will give you the current week number
PHP Code:

echo date('W'); 

Reply With Quote
  #6 (permalink)  
Old 10-27-04, 06:47 AM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
Since I'm in an inventive mood, let's see what my brain can patch together.

Ok, so we know there are about 7 days in a week, yes? And if there are 42 weeks gone by, there are 42*7 days (294)

So we've established the day of the year *but* it will be the same day as the start of the year, since we haven't done anything about the first day of the week or whatnot.

PHP Code:

mktime (0001294date("Y")) 

Now this is a disgusting little piece of code that will make your insides curl up and wiggle, but when I tried it out it accepted the "month=1", "day=294" and spat out the 20th of October, later confirmed as the 293rd day of the year. Hey, it's close enough.

Now we have wednesday the 20th of October, we need to sort out the first day of the week. Using date("w") will tell you that Wednesday is the 3rd day of the week (with Sunday as 0)

So now we can do the mktime function again, reducing the days by 3 to get the sunday of that week.

PHP Code:

mktime (0001291date("Y")) 

Sun Oct 17, 2004.
date("W") = 42nd week of the year.

Am I good or what?

Last edited by Sabu; 10-27-04 at 06:49 AM.
Reply With Quote
  #7 (permalink)  
Old 12-14-04, 02:14 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for taking the time to post your responce and it works great. My next step is to find the next day (i.e monday, tuesday, etc) by the "date('w) method

This is what I use at the moment to find the Day I want by the 0 - 6 system. What can i do to this script so instead from calculating the day from todays date it will do it by the week number?

PHP Code:

// Select Date Script

$day_of_event // assuming friday in this example  
$diff $day_of_event date('w'); 
$timestamp strtotime("+" $diff " days"); 

I guess I have to get rid of the date number of today ( date('w'); ) and replace it with the week number but that dont seem to work!
Reply With Quote
  #8 (permalink)  
Old 12-14-04, 02:25 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
somthing like this maybe? Dont work though

PHP Code:

// Get the first day of the week I want.

$week_day = ($promo['weekno'] * 7);
$week_no mktime (0001week_daydate("Y"));
 
// Select Date Script
$day_of_event $promo['daysID']; // assuming friday in this example  
$diff $day_of_event date('w'$week_no); 
$timestamp strtotime("+" $diff " days"); 
Reply With Quote
  #9 (permalink)  
Old 12-26-04, 04:53 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
BUMP BUMP.. Anyone?
Reply With Quote
  #10 (permalink)  
Old 01-03-05, 11:25 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
If no one knows what im trying to do. Please post a responce and I'll try to explain better.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
add a number every 30 minutes Dion PHP 5 08-31-04 12:52 AM
Loop - Convert number into day of the week dihan PHP 12 06-30-04 04:28 AM
ASP.NET: Day / Work Week / Week / Month web calendar control with view like MS Outloo gicio ASP.NET 2 06-09-04 02:12 AM
Add sequential number to database from checkbox ajndede ASP 1 05-04-04 07:43 AM
Need day of year from ISO-8601 week number. matt.simpson PHP 1 01-20-04 01:04 PM


All times are GMT -5. The time now is 04:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.