SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get date from monday and friday for the week by selecting month and year in php

    Get date from monday and friday for the week by selecting month and yea in php. Is it possible?

    Let me know if anybody didn't understand my question.Thanks

  2. #2
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Attached image is what I am looking for depending on month and year you choose..Thanks in advance..
    Attached Images Attached Images

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    There would be 3 or 4 (or 5) mondays and fridays in a given month of a given year. Which are you looking for?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All the Mondays in given a month for specific year..I am not sure if you can see the image..

    http://www.sitepoint.com/forums/atta...7&d=1342723339

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    All Mondays in a Given Month:

    PHP Code:
    $time strtotime("first Monday of ".$monthname." ".$year); 
    while(
    $time <= strtotime("last Monday of ".$monthname." ".$year)) {
     echo 
    date('jS',$time)." ".$monthname;
     
    $time += (7*24*60*60); //Advance One Week.

    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  6. #6
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply it did help but I wanted all the weeks in a month selected for that year Like Monday to Friday.
    Attached Images Attached Images

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    How are you defining a week-in-a-month? What if the month ends on a Wednesday? Do you want the Mon-Wed of that week too? Or the whole week? What about if it begins on a wednesday?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  8. #8
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    How are you defining a week-in-a-month? What if the month ends on a Wednesday? Do you want the Mon-Wed of that week too? Or the whole week? What about if it begins on a wednesday?
    Yes that's correct.Week is from Monday to Wednesday and in next month First week it will show from Thursday

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    So you want all weekdays in the month. Okay...

    PHP Code:
    $time strtotime("first day of ".$monthname." ".$year); 
    while(
    $time <= strtotime("last day of ".$monthname." ".$year)) {
     if((
    date('w',$time) + 1) % 1) { //It's a weekday. 0 = Saturday, 1 = Sunday.
       
    echo date('jS',$time)." ".$monthname;
     }
     
    $time += (24*60*60); //Advance One Day

    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •