| | |
Regardind display of second and fouth saturdays
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Maybe check the examples at date() and time() functions at php.net?
Maybe example of your problem would help also.
Maybe example of your problem would help also.
"You never stop learning." - OmniX
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 Syntax (Toggle Plain Text)
<?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; ?>
•
•
Join Date: Apr 2009
Posts: 254
Reputation:
Solved Threads: 37
yes strtotime function is perfect of time calculations.
For example
For example
php Syntax (Toggle Plain Text)
$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;
Last edited by peter_budo; Apr 6th, 2009 at 3:49 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Apr 2009
Posts: 254
Reputation:
Solved Threads: 37
try it.
php Syntax (Toggle Plain Text)
$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; }
Last edited by peter_budo; Apr 6th, 2009 at 3:50 pm. Reason: Please use [code] instead of [quote]
![]() |
Other Threads in the PHP Forum
- Previous Thread: Sending email via PHP
- Next Thread: Timed Out Logout
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube





