943,569 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 886
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 3rd, 2009
0

Regardind display of second and fouth saturdays

Expand Post »
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.
Reputation Points: 16
Solved Threads: 2
Light Poster
srilakshmitr7 is offline Offline
32 posts
since Aug 2008
Apr 3rd, 2009
0

Re: Regardind display of second and fouth saturdays

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

Maybe example of your problem would help also.
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007
Apr 4th, 2009
0

Re: Regardind display of second and fouth saturdays

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)
  1. <?PHP
  2.  
  3.  
  4. $wk = strtotime ("first saturday may 2009");
  5.  
  6. if ($wk == false) {
  7. echo "<br>Not able to interpret the string ";
  8. exit;
  9. }
  10.  
  11. $sat2 = $wk + (3600*24*7); // add seven days (in seconds)
  12.  
  13. $sat4 = $sat2 + (3600*24*14); // add 14 days
  14.  
  15. $wk2 = date ("Y-m-d",$sat4);
  16.  
  17. echo $wk2;
  18.  
  19. ?>
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Apr 6th, 2009
0

Re: Regardind display of second and fouth saturdays

yes strtotime function is perfect of time calculations.

For example

php Syntax (Toggle Plain Text)
  1. $today=date('Y-m-d');// for example today is 2009-04-06
  2. $newdate=strtotime ($today);// converted to strtotime
  3.  
  4. $newdate1= $newdate+ (3600*24*7); // add 7 days
  5. $newdate2= $newdate+ (3600*24*14); // add 14 days
  6.  
  7. $day= date ("D",$newdate1); // DAY after 7 days
  8. $day2= date ("D",$newdate2); // DAY after 14 days
  9.  
  10. echo "after 7 days the Day will be.".$day;
  11. 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.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 6th, 2009
0

Re: Regardind display of second and fouth saturdays

I want to display second and fourth saturdays not the day after 7th and 14th days.
Reputation Points: 16
Solved Threads: 2
Light Poster
srilakshmitr7 is offline Offline
32 posts
since Aug 2008
Apr 6th, 2009
0

Re: Regardind display of second and fouth saturdays

try it.
php Syntax (Toggle Plain Text)
  1.  
  2. $mysat=1;
  3. $current_year=date('Y');
  4. $current_month=date('m');
  5.  
  6. for($i=1; $i<=31; $i++)
  7. {
  8. $mydate=$current_year."-".$current_month."-".$i;
  9. $newdate=strtotime ($mydate);
  10. $saturday= date("w",$newdate);//Numeric representation of the day of the week . 0 (for Sunday) through 6 (for Saturday)
  11.  
  12. if($saturday==6)
  13. {
  14. if($mysat==2)
  15. {
  16. echo "<br>my 2nd saturdays is--".$mydate;
  17. }
  18. if($mysat==4)
  19. {
  20. echo "<br>my 4th saturdays is--".$mydate;
  21. }
  22. $mysat+=1;
  23. }
Last edited by peter_budo; Apr 6th, 2009 at 3:50 pm. Reason: Please use [code] instead of [quote]
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 6th, 2009
0

Re: Regardind display of second and fouth saturdays

I already tried this method but in different way but no results.
Reputation Points: 16
Solved Threads: 2
Light Poster
srilakshmitr7 is offline Offline
32 posts
since Aug 2008
Apr 6th, 2009
0

Re: Regardind display of second and fouth saturdays

I already tried this method but in different way but no results.
i tried it at my end. please try it now.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 6th, 2009
0

Re: Regardind display of second and fouth saturdays

try this code please. it will give you the 2nd and 4th Saturday. if you have any further issue please explain that
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 6th, 2009
0

Re: Regardind display of second and fouth saturdays

i have edited the code for you. please try and tell what happened?
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Sending email via PHP
Next Thread in PHP Forum Timeline: Timed Out Logout





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC