strtotime - Monday of current week - PHP

This is a discussion on strtotime - Monday of current week - PHP ; I am trying to output Monday of the current week i.e. if Monday is the 8th I want to display 'Monday 8th' for any date between Monday 8-14th. I would appreciate any help, the code below is heading in the ...

+ Reply to Thread
Results 1 to 6 of 6

strtotime - Monday of current week

  1. Default strtotime - Monday of current week

    I am trying to output Monday of the current week i.e. if Monday is the
    8th I want to display 'Monday 8th' for any date between Monday 8-14th.

    I would appreciate any help, the code below is heading in the right
    direction but doesn't quite give me the results I am looking for.

    $givenday = mktime(0,0,0,10,08,2007);
    $Monday = strtotime("Monday this week",$givenday);
    echo date("j M Y H:i:s", $Monday);

    Cheers,

    Chris


  2. Default Re: strtotime - Monday of current week

    In our last episode,
    <1192140304.180826.282650@g4g2000hsf.googlegroups.com>,
    the lovely and talented Chris
    broadcast on comp.lang.php:

    > I am trying to output Monday of the current week i.e. if Monday is the
    > 8th I want to display 'Monday 8th' for any date between Monday 8-14th.


    > I would appreciate any help, the code below is heading in the right
    > direction but doesn't quite give me the results I am looking for.


    > $givenday = mktime(0,0,0,10,08,2007);
    > $Monday = strtotime("Monday this week",$givenday);
    > echo date("j M Y H:i:s", $Monday);


    > Cheers,


    > Chris


    This seems to work for me.

    php -r "echo date('j M Y H:i:s',strtotime('last Monday', \
    strtotime('Sunday')));"

    You want the Monday previous to next Sunday.

    --
    Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
    Countdown: 466 days to go.
    What do you do when you're debranded?

  3. Default Re: strtotime - Monday of current week

    <comp.lang.php>
    <Chris>
    <Thu, 11 Oct 2007 15:05:04 -0700>
    <1192140304.180826.282650@g4g2000hsf.googlegroups.com>

    > I am trying to output Monday of the current week i.e. if Monday is the
    > 8th I want to display 'Monday 8th' for any date between Monday 8-14th.
    >
    > I would appreciate any help, the code below is heading in the right
    > direction but doesn't quite give me the results I am looking for.
    >
    > $givenday = mktime(0,0,0,10,08,2007);
    > $Monday = strtotime("Monday this week",$givenday);
    > echo date("j M Y H:i:s", $Monday);
    >


    <?php

    $less=0;

    $loopy=1;
    while ($loopy<8)
    {
    $temp1=date("l dS",time()-$less);
    $temp2=date("l dS M Y H:i:s",time()-$less);
    $wsx=" $temp1 "; $qaz=strpos($wsx,"Monday"); if ($qaz==true) {break;}
    $less=$less+86400;
    $loopy=$loopy+1;
    }

    print "temp1 = $temp1 <br>";
    print "temp2 = $temp2 <br>";

    ?>


    --
    www.vhit.co.uk
    www.jpgimage.co.uk
    www.phpwhois.co.uk
    www.cannabiswindow.co.uk

  4. Default Re: strtotime - Monday of current week

    On Oct 11, 11:29 pm, Lars Eighner <use...@larseighner.com> wrote:
    > In our last episode,
    > <1192140304.180826.282...@g4g2000hsf.googlegroups.com>,
    > the lovely and talented Chris
    > broadcast on comp.lang.php:
    >
    > > I am trying to output Monday of the current week i.e. if Monday is the
    > > 8th I want to display 'Monday 8th' for any date between Monday 8-14th.
    > > I would appreciate any help, the code below is heading in the right
    > > direction but doesn't quite give me the results I am looking for.
    > > $givenday = mktime(0,0,0,10,08,2007);
    > > $Monday = strtotime("Monday this week",$givenday);
    > > echo date("j M Y H:i:s", $Monday);
    > > Cheers,
    > > Chris

    >
    > This seems to work for me.
    >
    > php -r "echo date('j M Y H:i:s',strtotime('last Monday', \
    > strtotime('Sunday')));"
    >
    > You want the Monday previous to next Sunday.
    >
    > --
    > Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
    > Countdown: 466 days to go.
    > What do you do when you're debranded?


    Cheers Lars!

    I wanted a link to show this monday, then the next etc. Your code
    helped, will continue to build on it.

    $monday = date('j M Y', strtotime('last Monday',
    strtotime('Sunday')));
    $unixtime_monday = strtotime($monday);
    $next_monday = date('j M Y', strtotime('+1 week', $unixtime_monday));

    Chris


  5. Default Re: strtotime - Monday of current week

    On Sun, 14 Oct 2007 21:24:24 +0200, Chris <matchett123@googlemail.com>
    wrote:

    > On Oct 11, 11:29 pm, Lars Eighner <use...@larseighner.com> wrote:
    >> In our last episode,
    >> <1192140304.180826.282...@g4g2000hsf.googlegroups.com>,
    >> the lovely and talented Chris
    >> broadcast on comp.lang.php:
    >>
    >> > I am trying to output Monday of the current week i.e. if Monday is the
    >> > 8th I want to display 'Monday 8th' for any date between Monday 8-14th.
    >> > I would appreciate any help, the code below is heading in the right
    >> > direction but doesn't quite give me the results I am looking for.
    >> > $givenday = mktime(0,0,0,10,08,2007);
    >> > $Monday = strtotime("Monday this week",$givenday);
    >> > echo date("j M Y H:i:s", $Monday);
    >> > Cheers,
    >> > Chris

    >>
    >> This seems to work for me.
    >>
    >> php -r "echo date('j M Y H:i:s',strtotime('last Monday', \
    >> strtotime('Sunday')));"
    >>
    >> You want the Monday previous to next Sunday.
    >>
    >> --
    >> Lars Eighner <http://larseighner.com/>
    >> <http://myspace.com/larseighner>
    >> Countdown: 466 days to go.
    >> What do you do when you're debranded?

    >
    > Cheers Lars!
    >
    > I wanted a link to show this monday, then the next etc. Your code
    > helped, will continue to build on it.
    >
    > $monday = date('j M Y', strtotime('last Monday',
    > strtotime('Sunday')));
    > $unixtime_monday = strtotime($monday);



    Euhm, what am I missing?

    $monday = date('j M Y', strtotime('last Monday',strtotime('Sunday')));
    $unixtime_monday = strtotime($monday);

    Would be equal to:

    $unixtime_monday = strtotime('last Monday',strtotime('Sunday'));

    is it not?
    --
    Rik Wasmus

  6. Default Re: strtotime - Monday of current week

    In our last episode, <1192389864.882127.326370@e9g2000prf.googlegroups.com>,
    the lovely and talented Chris broadcast on comp.lang.php:

    > On Oct 11, 11:29 pm, Lars Eighner <use...@larseighner.com> wrote:
    >> In our last episode,
    >> <1192140304.180826.282...@g4g2000hsf.googlegroups.com>,
    >> the lovely and talented Chris
    >> broadcast on comp.lang.php:
    >>
    >> > I am trying to output Monday of the current week i.e. if Monday is the
    >> > 8th I want to display 'Monday 8th' for any date between Monday 8-14th.
    >> > I would appreciate any help, the code below is heading in the right
    >> > direction but doesn't quite give me the results I am looking for.
    >> > $givenday = mktime(0,0,0,10,08,2007);
    >> > $Monday = strtotime("Monday this week",$givenday);
    >> > echo date("j M Y H:i:s", $Monday);
    >> > Cheers,
    >> > Chris

    >>
    >> This seems to work for me.
    >>
    >> php -r "echo date('j M Y H:i:s',strtotime('last Monday', \
    >> strtotime('Sunday')));"
    >>
    >> You want the Monday previous to next Sunday.


    > Cheers Lars!


    > I wanted a link to show this monday, then the next etc. Your code
    > helped, will continue to build on it.


    > $monday = date('j M Y', strtotime('last Monday',
    > strtotime('Sunday')));
    > $unixtime_monday = strtotime($monday);
    > $next_monday = date('j M Y', strtotime('+1 week', $unixtime_monday));


    Yes, but php strtotime already knows 'next Monday':

    Sun Oct 14 15:33:54 bash3.2:ttyp0:lars
    debranded~$php -r "echo date('j M Y',strtotime('next Monday'));"
    15 Oct 2007

    (Yes, it is broken if your php is older than 4.4.0)

    The problem part of your original problem was that strtotime doesn't know
    something like "Monday of this week". The difficulty of implementing that
    in the strtotime function would be that people would have different
    understandings of what they mean by 'this week.' For example, your problem
    involves the work week (of which Sunday is the last day). Most Western
    calendars use a week that ends on Saturday. You might well consider Jan. 1
    to be the first day of the first week.


    And it has been mentioned that:

    > $monday = date('j M Y', strtotime('last Monday',
    > strtotime('Sunday')));
    > $unixtime_monday = strtotime($monday);


    is the same as

    > $unixtime_monday = strtotime('last Monday', strtotime('Sunday')));


    There is no point in going string to time and back.

    So even if you have old php (or want to be backwards compatible with
    broken versions)

    $next_monday = date('j M Y', strtotime('+1 week',
    strtotime('last Monday', strtotime('Sunday'))));



    --
    Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
    Countdown: 463 days to go.
    What do you do when you're debranded?

+ Reply to Thread

Similar Threads

  1. Slow performance using strtotime on prior 1970 dates
    By Application Development in forum PHP
    Replies: 5
    Last Post: 09-14-2007, 04:08 PM
  2. Monday -Friday work week sharepoint calendar
    By Application Development in forum Sharepoint
    Replies: 0
    Last Post: 07-27-2007, 12:00 PM
  3. OSCON Early Reg Deadline: May 20 (this Monday!)
    By Application Development in forum Python
    Replies: 0
    Last Post: 06-16-2005, 02:17 PM
  4. Display week days of current week
    By Application Development in forum CSharp
    Replies: 1
    Last Post: 04-18-2005, 11:03 AM
  5. Help! Deadline Monday! Simple database
    By Application Development in forum basic.visual
    Replies: 3
    Last Post: 01-08-2005, 04:10 PM