| | |
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
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web webdesign websphere white xml youtube





