Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weekly date!? Pls Help

Status
Not open for further replies.

Forri

Programmer
Joined
Oct 29, 2003
Messages
479
Location
MT
Hi all

I'm trying to get a set of dates (array) when a user selects a Start Date, End Date and the week Days (Mon-Sun).

So to understand me better:

Start day: 01/05/2004 (ie: Sat 5th May 2004)
End Day : 15/05/2004 (ie: Sat 15the May 2004)

Days Selected = "Mon and Wed"

Output: (the array should contain)

03/05/2004 (Monday)
05/05/2004 (Wed)
10/05/2004 (Monday)
12/05/2004 (Wed)

Can you help me contruct a function for this!?

Thanks
Ncik
 
get startdate;
get enddate;
get daysselected;
convert startdate to startdays;
convert enddate to startdays;
for i = startdays to enddays;
Convert i to day_of_week;
if day_of_week in daysselected[]
add i into showdates[];
fi
next;
 
May not be efficient one but will solve your purpose

Code:
<?php

  $userselecteddate = array() ;
  $userselecteddate[0] = "Mon" ;
  $userselecteddate[1] = "Wed" ;

  $sdate =  "01/05/2004" ;// (ie: Sat 5th May 2004)
  $edate =  "15/05/2004" ;  //(ie: Sat 15the May 2004)

  list( $sday,$smon,$syear ) = explode( "/",$sdate ) ;
  list( $eday,$emon,$eyear ) = explode( "/",$edate ) ;

  $totdays =  ( mktime( 0,0,0,$emon,$eday,$eyear ) - mktime( 0,0,0,$smon,$sday,$syear ) ) / (24 * 60 * 60) ;


   for($i=0; $i<$totdays; $i++) {
   	$date = (date('d/m/Y',mktime( 0,0,0,$smon,$sday,$syear )+(60*60*24*$i)).'<br>');

    list( $day,$mon,$year ) = explode( "/",$date ) ;

    if ( in_array(date("D",mktime( 0,0,0,$mon,$day,$year ) ),$userselecteddate ) ) echo $date ;
   }




?>

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top