www.webdeveloper.com
Results 1 to 2 of 2

Thread: Can strtotime() be used with other variables?

  1. #1
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    265

    Question Can strtotime() be used with other variables?

    Can I use strtotime() with other variables... for example:

    PHP Code:
    $lastMonday strtotime("last Monday"); 
    Could I then find "3 days before that" or various other things from the result given as the variable "lastMonday"?

    It has to be executable from any day... So for example if it's sun/mon/tue/wed/thu and you want to find when the last Friday was and then count back to 4 days prior for the "monday" of last week and ALSO have separate variables displaying each day from last week (monday-sunday) and the current week... (or other weeks)

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    The second (optional) parameter is a UNIX timestamp integer, which is what strtotime() returns, so you could chain them together if needed, e.g.:
    PHP Code:
    $dateTime strtotime('-3 days'strtotime('Last Monday')); 
    Since date() also accepts the same optional 2nd parameter, you could even output that result in "human readable" format as:
    PHP Code:
    echo date('Y-m-d H:i:s'strtotime('-3 days'strtotime('Last Monday'))); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles