SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Romania
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get first and last day of the last week

    Hello guys!

    How can I get the first (monday) and the last (sunday) day of the last week?

    Thanks!

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Do you mean the dates of them?

    PHP Code:
    $Sunday Date('d/m/y'StrToTime("Next Sunday"));
    $Monday Date('d/m/y'StrToTime("Last Monday")); 
    Edit:

    Though that'd have problems on Sundays and Mondays, so you could try:
    PHP Code:
    $Current Date('N');
    $DaysToSunday $Current;
    $DaysFromMonday $Current 1;
    $Sunday Date('d/m/y'StrToTime("+ {$DaysToSunday} Days"));
    $Monday Date('d/m/y'StrToTime("- {$DaysFromMonday} Days")); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2003
    Location
    Romania
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, the dates. Works like a charm, thanks!

  4. #4
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    If you mean "of the last full week", then you could do:

    PHP Code:
    $monday date('d/m/y'strtotime('monday last week'));
    $sunday date('d/m/y'strtotime('sunday last week')); 
    Salathe
    Software Developer and PHP Manual Author.


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
  •