Results 1 to 2 of 2

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

  1. #1
    Join Date
    Apr 2011
    Seattle, WA

    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
    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'))); 
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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