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.

Recommended Answers

All 11 Replies

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

Maybe example of your problem would help also.

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 "<br>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;

?>

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;

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

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 "<br>my 2nd saturdays is--".$mydate;
				}
				if($mysat==4)
				{
				echo "<br>my 4th saturdays is--".$mydate;
				}
	        $mysat+=1;
	        }

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

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

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

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

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

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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.