Get date based on weekday?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dr. zoidberg

    Get date based on weekday?

    Hello,

    I have this:

    Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to
    do is to associate days with its current week dates, for example:

    Mon (05.01.2004); Tue (06.01.2004); and so on.

    TNX

  • mjacob

    #2
    Re: Get date based on weekday?

    "dr. zoidberg" <someone@14.u7. da.ru> wrote in message news:<G7KKb.698 2$JB2.2866@ns45 .bih.net.ba>...[color=blue]
    > Hello,
    >
    > I have this:
    >
    > Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to
    > do is to associate days with its current week dates, for example:
    >
    > Mon (05.01.2004); Tue (06.01.2004); and so on.
    >
    > TNX[/color]

    I'm not quite sure what you're trying to accomplish, but you could
    always use the date() function.

    Comment

    • dr. zoidberg

      #3
      Re: Get date based on weekday?

      mjacob wrote:
      [color=blue]
      > "dr. zoidberg" <someone@14.u7. da.ru>
      >[color=green]
      >>Hello,
      >>
      >>I have this:
      >>
      >>Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to
      >>do is to associate days with its current week dates, for example:
      >>
      >>Mon (05.01.2004); Tue (06.01.2004); and so on.
      >>
      >>TNX[/color]
      >
      >
      > I'm not quite sure what you're trying to accomplish, but you could
      > always use the date() function.[/color]

      I'm trying do display weekdays with dates, monday to sunday, but only
      for current week, something like small calendar.

      Comment

      • Pedro Graca

        #4
        Re: Get date based on weekday?

        dr. zoidberg wrote:[color=blue]
        > I'm trying do display weekdays with dates, monday to sunday, but only
        > for current week, something like small calendar.[/color]

        <?php
        $wd_arr = array('Mo ', 'Tu ', 'We ', 'Th ', 'Fr ', 'Sa ', 'Su ');
        $monday = mktime(0, 0, 0, // hour, minute, second
        (int)date('m'), // month
        (int)date('d')+ (1-(int)date('w')) , // day (can be negative!)
        (int)date('Y')) ; // year

        for ($n=0; $n<7; $n++) {
        echo $wd_arr[$n], date('Y-m-d', $monday+$n*60*6 0*24), "<br/>\n";
        }
        ?>
        --
        --= my mail box only accepts =--
        --= Content-Type: text/plain =--
        --= Size below 10001 bytes =--

        Comment

        • Christopher Vogt

          #5
          Re: Get date based on weekday?

          dr. zoidberg schrieb:[color=blue]
          > mjacob wrote:
          >[color=green]
          >> "dr. zoidberg" <someone@14.u7. da.ru>
          >>[color=darkred]
          >>> Hello,
          >>>
          >>> I have this:
          >>>
          >>> Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to
          >>> do is to associate days with its current week dates, for example:
          >>>
          >>> Mon (05.01.2004); Tue (06.01.2004); and so on.
          >>>
          >>> TNX[/color]
          >>
          >>
          >>
          >> I'm not quite sure what you're trying to accomplish, but you could
          >> always use the date() function.[/color]
          >
          >
          > I'm trying do display weekdays with dates, monday to sunday, but only
          > for current week, something like small calendar.
          >[/color]

          Hi mjacob,

          i hope this code snippet will help you. I just wrote it down in this
          mail, maybe some things do not work instantly but it should at least
          show you the way:


          // CODE START
          switch($weekday ) // $weekday should contain "Sun" or "Mon" and so on
          {
          case "Sun":
          $weekdaynr = 0; // assign a nr representing the weekday
          break;
          case "Mon":
          $weekdaynr = 1;
          break;

          // ... and so on ...

          }

          $todaynr = date("w"); // assign the today weekday
          $day_diff = $todaynr - $weekdaynr; // get the difference in days
          $sec_diff = $daydiff * 24 * 60 * 60; // get the difference in seconds
          $target_date = mktime() - $sec_diff; // actual timestamp - difference
          echo date ("D (d.M.Y)", $target_date); // output newly formatted date
          // CODE END



          you can also use strftime() for more format options


          Have a nice day,
          Chris

          Comment

          • Ian.H

            #6
            Re: Get date based on weekday?

            On Wed, 07 Jan 2004 16:16:35 +0100, dr. zoidberg wrote:
            [color=blue]
            > I'm trying do display weekdays with dates, monday to sunday, but only for
            > current week, something like small calendar.[/color]

            DZ..

            Check out <http://www.phpbuilder. com/> and do a quick search / hunt for a
            calendar app / code on there. One does exist.

            Pre-warning... the code doesn't work 100% as it's entered on the site.. I
            tried to use it a while back but broke horrible, however, it does have the
            data / "formula" for displaying dates relative to days (including "empty
            ones".. ie: it knows the start day of the month and the end day for
            example) and might help you on your way to what you're aiming for =)


            HTH.



            Regards,

            Ian

            --
            Ian.H [Design & Development]
            digiServ Network - Web solutions
            www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
            Programming, Web design, development & hosting.

            Comment

            • dr. zoidberg

              #7
              [solved] Re: Get date based on weekday?

              Pedro Graca wrote:
              [color=blue]
              > dr. zoidberg wrote:
              >[color=green]
              >>I'm trying do display weekdays with dates, monday to sunday, but only
              >>for current week, something like small calendar.[/color]
              >
              >
              > <?php
              > $wd_arr = array('Mo ', 'Tu ', 'We ', 'Th ', 'Fr ', 'Sa ', 'Su ');
              > $monday = mktime(0, 0, 0, // hour, minute, second
              > (int)date('m'), // month
              > (int)date('d')+ (1-(int)date('w')) , // day (can be negative!)
              > (int)date('Y')) ; // year
              >
              > for ($n=0; $n<7; $n++) {
              > echo $wd_arr[$n], date('Y-m-d', $monday+$n*60*6 0*24), "<br/>\n";
              > }
              > ?>[/color]

              Great script.

              Few adjustment and I created what I want. TNX

              Comment

              Working...