954,160 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Regardind display of second and fouth saturdays

Can any one give me some idea regarding how to calculate second and fourth saturdays i did based on time whenever i change system time it results in tuesdays insetad of saturdays.

srilakshmitr7
Light Poster
32 posts since Aug 2008
Reputation Points: 16
Solved Threads: 2
 

Maybe check the examples at date() and time() functions at php.net?

Maybe example of your problem would help also.

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

The strtotime function is useful for this sort of thing. Here is a little routine that calculates the 2nd and 4th Saturdays in May (as an example):

<?PHP


	$wk = strtotime ("first saturday may 2009");
	
	if ($wk == false) {
		echo "Not able to interpret the string ";
		exit;
	}
	
	$sat2	= $wk + (3600*24*7);				// add seven days  (in seconds)

	$sat4	= $sat2 + (3600*24*14);				// add 14 days

	$wk2 = date ("Y-m-d",$sat4);
	
	echo $wk2;

?>
chrishea
Nearly a Posting Virtuoso
1,427 posts since Sep 2008
Reputation Points: 210
Solved Threads: 230
 

yes strtotime function is perfect of time calculations.

For example

$today=date('Y-m-d');// for example today is 2009-04-06
$newdate=strtotime ($today);// converted to strtotime

$newdate1= $newdate+ (3600*24*7);	// add 7 days
$newdate2= $newdate+ (3600*24*14);	// add 14 days

$day= date ("D",$newdate1); // DAY after 7 days
$day2= date ("D",$newdate2); // DAY after 14 days

echo "after 7 days the Day will be.".$day;
echo "after 14 days the Day will be.".$day2;
BzzBee
Posting Whiz
327 posts since Apr 2009
Reputation Points: 16
Solved Threads: 48
 

I want to display second and fourth saturdays not the day after 7th and 14th days.

srilakshmitr7
Light Poster
32 posts since Aug 2008
Reputation Points: 16
Solved Threads: 2
 

try it.

$mysat=1;
$current_year=date('Y');
$current_month=date('m');

for($i=1; $i<=31; $i++)
{
$mydate=$current_year."-".$current_month."-".$i;
$newdate=strtotime ($mydate);
$saturday= date("w",$newdate);//Numeric representation of the day of the week  . 0 (for Sunday) through 6 (for Saturday)
	
	       if($saturday==6)
	        {
				if($mysat==2)
				{
				echo "my 2nd saturdays is--".$mydate;
				}
				if($mysat==4)
				{
				echo "my 4th saturdays is--".$mydate;
				}
	        $mysat+=1;
	        }
BzzBee
Posting Whiz
327 posts since Apr 2009
Reputation Points: 16
Solved Threads: 48
 

I already tried this method but in different way but no results.

srilakshmitr7
Light Poster
32 posts since Aug 2008
Reputation Points: 16
Solved Threads: 2
 
I already tried this method but in different way but no results.

i tried it at my end. please try it now.

BzzBee
Posting Whiz
327 posts since Apr 2009
Reputation Points: 16
Solved Threads: 48
 

try this code please. it will give you the 2nd and 4th Saturday. if you have any further issue please explain that :)

BzzBee
Posting Whiz
327 posts since Apr 2009
Reputation Points: 16
Solved Threads: 48
 

i have edited the code for you. please try and tell what happened?

BzzBee
Posting Whiz
327 posts since Apr 2009
Reputation Points: 16
Solved Threads: 48
 

Show us your code if there are problems with it.

Quick look the previous code should work.

Like i said should work using the date() and time() functions depending on what your requirements are?

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

Thank you so much for your help i got the answer.

srilakshmitr7
Light Poster
32 posts since Aug 2008
Reputation Points: 16
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You