mktime() First Day of the Last Week

The mktime() function returns the Unix timestamp for a date.
This timestamp contains the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.

Assumed Moday is the firstday of the week.

//YESTERDAY
$yesterday = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m')  , date('d')-1, date('Y')));

//THIS WEEK
$fromDate = date('Y-m-d H:i:s',mktime(0, 0, 0, date('n'), date('j'), date('Y')) - ((date('N')-1)*3600*24));
$toDate = CURRENT_TIMESTAMP;

//LAST WEEK
$fromDate = date('Y-m-d H:i:s',mktime(0, 0, 0, date('n'), date('j')-6, date('Y')) - ((date('N'))*3600*24));
$toDate = date('Y-m-d H:i:s',mktime(23, 59, 59, date('n'), date('j'), date('Y')) - ((date('N'))*3600*24));

//THIS MONTH
$fromDate = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m')  , 1, date('Y')));
$toDate = CURRENT_TIMESTAMP;

//LAST MONTH
$fromDate = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m')-1  , 1 , date('Y')));
$toDate = date('Y-m-d H:i:s',mktime(23, 59, 59, date('m'), date('d')-date('j'), date('Y')));

//THIS YEAR
$fromDate = date('Y-m-d H:i:s',mktime(0, 0, 0, date(1)  , date(1), date('Y')));
$toDate = CURRENT_TIMESTAMP;

//LAST YEAR
$fromDate = date('Y-m-d H:i:s',mktime(0, 0, 0, 1  , 1, date('Y')-1));
$toDate = date('Y-m-d H:i:s',mktime(23, 59, 59, 12, 31, date('Y')-1));

enjoy 😉

Advertisements

About Tanveer
RIA (Rich Internet Application) Developer with a wide variety of business applications. Particularly interested in client/server and relational database design. Always interested in migration projects, as well as close interaction with the DB manufacturers.

7 Responses to mktime() First Day of the Last Week

  1. Alan Ihre says:

    Thanks, this really helped me! 😀

  2. Tips Kecantikan says:

    Thanks for some other informative web site.

    The place else may I get that kind of information written in such an ideal manner?
    I’ve a challenge that I am just now working on, and I have been on the glance out for such information.

  3. Jenni says:

    Right here is the perfect web site for anybody who really wants to find out about this topic.
    You know a whole lot its almost tough to argue with you (not that I really would want to…HaHa).
    You certainly put a fresh spin on a topic that has been discussed for many
    years. Excellent stuff, just wonderful!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: