| | |
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 |
# 5.2.10 action address apache api array auto autoincrement beginner binary broken cakephp checkbox class classes cms code cron curl database date dehasher destroy display dissertation domain dynamic echo echo$_get[x]changingitintovariable... email error errorlog fatalerror file files folder form forms function functions google href htaccess html if-else image images include insert ip javascript joomla legislation limit link load login mail masterthesis menu mlm multiple mysql mysqlquery oop open paypal pdf persist php popup problem query radio random record recursion remote script search server sessions sms sockets source space sql syntax system table tutorial update upload url validator variable video web youtube





