| | |
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: 257
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: 257
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
Views: 681 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download duplicates dynamic echo email error execution file files folder form forms function functions google href htaccess html htmlspecialchars image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php phpvotingscript problem query radio random recursion regex remote script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





