[eluser]Zack Kitzmiller[/eluser]
seriously, nothing fancy. just helpful. Allows for you to figure out relative dates. I use this helper all the time, so I thought you guys and gals may want to use it..
I know it could be a lot better, and check time preferences and what not, but nothing I do is that critical. Lemme know what you think.
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//---------- PAST Dates ----------
/**
* Get "yesterday"
*
* Returns yesterday's timestamp
*
* @access public
* @return integer
*/
if ( ! function_exists('yesterday'))
{
function yesterday()
{
return mktime(0, 0, 0, date("m"), date("d") - 1, date("Y"));
}
}
/**
* Get "last_week"
*
* Returns last week timestamp
*
* @access public
* @return integer
*/
if ( ! function_exists('two_weeks_previous'))
{
function last_week()
{
return mktime(0, 0, 0, date("m"), date("d") - 7, date("Y"));
}
}
/**
* Get "two_weeks_previous"
*
* Returns yesterday's timestamp
*
* @access public
* @return integer
*/
if ( ! function_exists('two_weeks_previous'))
{
function two_weeks_previous()
{
return mktime(0, 0, 0, date("m"), date("d") - 14, date("Y"));
}
}
/**
* Get "last_month"
*
* Returns last month's timestamp
*
* @access public
* @return integer
*/
if ( ! function_exists('last_month'))
{
function last_month()
{
return mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"));
}
}
/**
* Get "last_year"
*
* Returns last month's timestamp
*
* @access public
* @return integer
*/
if ( ! function_exists('last_month'))
{
function last_year()
{
return mktime(0, 0, 0, date("m"), date("d"), date("Y") - 1);
}
}
//---------- FUTURE DATES --------
/**
* Get "tomorrow"
*
* Returns tomorrow's timestamp
*
* @access public
* @return integer
*/
if ( ! function_exists('tomorrow'))
{
function tomorrow()
{
return mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
}
}
/**
* Get "next_week"
*
* Returns next_week's timestamp
*
* @access public
* @return integer
*/
if ( ! function_exists('next_week'))
{
function next_week()
{
return mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"));
}
}
/**
* Get "next_month"
*
* Returns next_month timestamp
*
* @access public
* @return integer
*/
if ( ! function_exists('next_month'))
{
function next_month()
{
return mktime(0, 0, 0, date("m") + 1, date("d"), date("Y"));
}
}
/**
* Get "next_year"
*
* Returns next_year timestamp
*
* @access public
* @return integer
*/
if ( ! function_exists('next_year'))
{
function next_year()
{
return mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1);
}
}