Date manipulation PLEASE

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

    Date manipulation PLEASE

    I have to do an events calender for a church. The events display will
    be limited to that week. If someone went in today Wed 24th I want to
    display 21st to 27th. I dont want any code samples, just the functions
    that find the day of week and a function that can (in this case)
    subtract 3 days to get sunday and add 7 for saterday. I can do the
    rest.

    Desmond.

  • Kimmo Laine

    #2
    Re: Date manipulation PLEASE

    "Des" <desotuatail@ao l.com> wrote in message
    news:1148464191 .266932.319310@ 38g2000cwa.goog legroups.com...[color=blue]
    >I have to do an events calender for a church. The events display will
    > be limited to that week. If someone went in today Wed 24th I want to
    > display 21st to 27th. I dont want any code samples, just the functions
    > that find the day of week and a function that can (in this case)
    > subtract 3 days to get sunday and add 7 for saterday. I can do the
    > rest.
    >[/color]

    I'd try something like this:

    $lastsunday = date('w')==0 ? mktime() : strtotime('last sunday');
    // If today _is_ sunday, then today, else last sunday
    echo date('Y-m-d',$lastsunday) ;

    $nextsaturday = strtotime('next saturday',$date forlastsunday);
    // Next saturday counting from the given sunday.
    echo date('Y-m-d',$lastsaturda y);

    strtotime is a pretty darn good way for getting expressional dates like
    "next month" or "last year" etc.

    --
    "ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
    spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)


    Comment

    • Des

      #3
      Re: Date manipulation PLEASE

      Well this kind of works. The code output i get is

      2006-05-21
      1970-01-01

      I don't think 1970 is the next saturday. Also I need this in a format
      suitable for an SQL Query.

      Des.

      Comment

      • Kimmo Laine

        #4
        Re: Date manipulation PLEASE

        "Des" <desotuatail@ao l.com> wrote in message
        news:1148466523 .938047.57880@j 55g2000cwa.goog legroups.com...[color=blue]
        > Well this kind of works. The code output i get is
        >
        > 2006-05-21
        > 1970-01-01
        >
        > I don't think 1970 is the next saturday. Also I need this in a format
        > suitable for an SQL Query.
        >
        > Des.
        >[/color]

        Sorry about that, and way to go with sarcasm by the way. (It always helps
        when someone is trying to _help_ you and you reply sarcastically "I don't
        think 1970 is next saturday"...) I first wrote the code using variable names
        $dateforlastsun day but then changed them to $lastsunday etc... Except in one
        critical place... :) Below is a working code with the typo fixed.

        $lastsunday = date('w')==0 ? mktime() : strtotime('last sunday');
        // If today _is_ sunday, then today, else last sunday
        echo date('Y-m-d',$lastsunday) ;

        $nextsaturday = strtotime('next saturday',$last sunday);
        // Next saturday counting from the given sunday.
        echo date('Y-m-d',$lastsaturda y);

        YYYY-mm-dd is a general date format that most databases do support and since
        you mentiond you can do the rest, I'm sure you'll be able to make with the
        correct date format on your own.

        Just in case: http://php.net/manual/en/function.date.php

        --
        "ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
        spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)


        Comment

        • Des

          #5
          Re: Date manipulation PLEASE

          Problem solved re-invent the wheel. add to functions to the include
          file

          function Sunday()
          {
          $day = 86400;
          $stamp = time();
          $sunday = date('w',$stamp );
          $stamp -= $day * $sunday;
          echo date('Y-m-d',$stamp);
          }

          function Saturday()
          {
          $day = 86400;
          $stamp = time();
          $sunday = date('w',$stamp );
          $sunday = 6 - $sunday;
          $stamp += $day * $sunday;
          echo date('Y-m-d',$stamp);
          }

          Comment

          • Rik

            #6
            Re: Date manipulation PLEASE

            Des wrote:[color=blue]
            > I have to do an events calender for a church. The events display will
            > be limited to that week. If someone went in today Wed 24th I want to
            > display 21st to 27th. I dont want any code samples, just the functions
            > that find the day of week and a function that can (in this case)
            > subtract 3 days to get sunday and add 7 for saterday. I can do the
            > rest.[/color]


            You don't want codesamples?
            Ok, return your day of the week with date() or strftime(), make dates with
            mktime().

            Grtz,
            --
            Rik Wasmus


            Comment

            Working...