473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

weekstart dates of a year

omerbutt
638 512MB
hi,
i am working on a reservations component in joomla 1.6, i have to provide the client with a form where he can enter the door codes for the Lodges , the door code changes on every monday and remains the same for the whole week , the table that holds the door codes,is as follows.

Expand|Select|Wrap|Line Numbers
  1. id
  2. code
  3. date_start
  4. date_end
  5.  
the date_start holds the starting day's date for the week i.e Monday obviously and the date_end holds the last day's date of the week i.e Sunday.

Now in the add new door code i have to provide the client with a drop-down that contains the list of the dates of every weeks Starting date up to 3 year in the future.
Any idea how to calculate the total mondays in a year as i need to loop and the loop needs to run up to Total mondays in the selected year,
Regards,
Omer Aslam
Nov 16 '11 #1

✓ answered by omerbutt

i changed it i provided the client with the drop down to select the year and then the month and after that i populated the drop down of all the dates for mondays in that particular month and year through ajax.
here is the core code for the weeks selection (Note: Joomla 1.6 component development)
Expand|Select|Wrap|Line Numbers
  1. public function getWeeks(){
  2.         $month    =    JRequest::getVar('month');
  3.         $year    =    JRequest::getVar('year');
  4.         $total_weeks    =    6;
  5.  
  6.         $start_date    =    new DateTime(date('Y-m-d',strtotime('first monday of '.$year.'-'.$month.'-01'))) ;
  7.         $end_date    =    new DateTime(date_format($start_date,'Y-m-d'));
  8.  
  9.         echo '<select name="weeks" id="weeks" onchange="putVal(this.value,\'date_start\');" class="required">';
  10.         echo '<option value="none">Select a Monday</option>';    
  11.         for($w=1; $w<=$total_weeks; $w++){
  12.             echo '<option value="'.date_format($end_date,'Y-m-d').'">'.date_format($end_date,'Y-m-d').'</option>';    
  13.             date_add($end_date, date_interval_create_from_date_string('7 days'));
  14.             if(date_format($end_date,'m')!=date_format($start_date,'m')){
  15.                 break;
  16.             }
  17.         }
  18.         echo '</select>';
  19.     }
  20.  
regards,
Omer Aslam

2 1799
zorgi
431 Expert 256MB
I would use time stamp for start date to make all calculations. Something like this:
Expand|Select|Wrap|Line Numbers
  1. $last_monday = strtotime("last Monday");
  2. //7 days * 24 hours * 60 minutes * 60 seconds = 604800 seconds
  3. $next_monday = $last_monday + 604800;
Nov 16 '11 #2
omerbutt
638 512MB
i changed it i provided the client with the drop down to select the year and then the month and after that i populated the drop down of all the dates for mondays in that particular month and year through ajax.
here is the core code for the weeks selection (Note: Joomla 1.6 component development)
Expand|Select|Wrap|Line Numbers
  1. public function getWeeks(){
  2.         $month    =    JRequest::getVar('month');
  3.         $year    =    JRequest::getVar('year');
  4.         $total_weeks    =    6;
  5.  
  6.         $start_date    =    new DateTime(date('Y-m-d',strtotime('first monday of '.$year.'-'.$month.'-01'))) ;
  7.         $end_date    =    new DateTime(date_format($start_date,'Y-m-d'));
  8.  
  9.         echo '<select name="weeks" id="weeks" onchange="putVal(this.value,\'date_start\');" class="required">';
  10.         echo '<option value="none">Select a Monday</option>';    
  11.         for($w=1; $w<=$total_weeks; $w++){
  12.             echo '<option value="'.date_format($end_date,'Y-m-d').'">'.date_format($end_date,'Y-m-d').'</option>';    
  13.             date_add($end_date, date_interval_create_from_date_string('7 days'));
  14.             if(date_format($end_date,'m')!=date_format($start_date,'m')){
  15.                 break;
  16.             }
  17.         }
  18.         echo '</select>';
  19.     }
  20.  
regards,
Omer Aslam
Nov 21 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: bad | last post by:
i´ve two variables the year and the week (2003 and 5) that means the 5th week of the year 2003. now i need the start- and enddate of the 5th week of year 2003. i hope someone can help me to...
9
by: Thomas W | last post by:
I'm developing a web-application where the user sometimes has to enter dates in plain text, allthough a format may be provided to give clues. On the server side this piece of text has to be parsed...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
3
by: Matt | last post by:
Hello, I have a query that I would like to schedule in DTS. The criteria of this query checks for records in the table that are within the current quarter. Here is what I have. WHERE...
7
by: Bambero | last post by:
Hello all Problem like in subject. There is no problem when I want to count days between two dates. Problem is when I want to count years becouse of leap years. For ex. between 2002-11-19...
3
by: David | last post by:
I'm new to DB2 and I need to write a query that will allow me to find specific dates instead of me having a date range asked for, I want it to be calculated. I've done this in Access by coding...
2
by: Douglas | last post by:
I have a Vehicle MOT field in my table which i have as a Date field I dont really want to hold the year, just 'dd mmm' as MOTs are the same date every year. I have the field on my form as a...
36
by: Lindie | last post by:
The more I read the more confused I get. Too much on dates calulations in the groups. I need to know how often a book has been loaned out over the past year- 52 weeks. My table has Book...
18
by: mlcampeau | last post by:
I have a lengthy query that I am now trying to filter. The query calculates an employee's Anniversary Date in which they are eligible for the next level of Annual Vacation. (i.e. For 1-6 years of...
8
by: hansnext | last post by:
I am "writing" a boolean function in VBA (Access 2003)to test whether a date entered by user is within the financial year that a project is planned for - the financial year runs from 1 July YYYY to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.