|
|
|
|
|
Get date range by this week, last week, this month, and last month options by providing offsets.
| <?php
function getWeekRange(&$start_date, &$end_date, $offset=0) {
$start_date = '';
$end_date = '';
$week = date('W');
$week = $week - $offset;
$date = date('Y-m-d');
$i = 0;
while(date('W', strtotime("-$i day")) >= $week) {
$start_date = date('Y-m-d', strtotime("-$i day"));
$i++;
}
list($yr, $mo, $da) = explode('-', $start_date);
$end_date = date('Y-m-d', mktime(0, 0, 0, $mo, $da + 6, $yr));
}
function getMonthRange(&$start_date, &$end_date, $offset=0) {
$start_date = '';
$end_date = '';
$date = date('Y-m-d');
list($yr, $mo, $da) = explode('-', $date);
$start_date = date('Y-m-d', mktime(0, 0, 0, $mo - $offset, 1, $yr));
$i = 2;
list($yr, $mo, $da) = explode('-', $start_date);
while(date('d', mktime(0, 0, 0, $mo, $i, $yr)) > 1) {
$end_date = date('Y-m-d', mktime(0, 0, 0, $mo, $i, $yr));
$i++;
}
}
getWeekRange($start, $end);
echo "$start $end";
getMonthRange($start, $end);
echo "$start $end";
?> | | |
|
| Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used. Categories : HTML and PHP, PHP, Date Time | | | Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL | | | Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields Categories : MySQL, Date Time, PHP, Databases | | | function to generate calendars on the fly.
Categories : Calendar, PHP, Date Time | | | If you want to create select buttons featuring current date this example will show you how... Categories : Date Time, HTML and PHP, PHP | | | Change the background color of a website daily dynamically using the php date function to get the current day of the week and depending on that day, set the background color for the web page. Categories : PHP, Date Time, Beginner Guides, Web Design | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | table calendar pretty much does what cal(1) does - prints out a calendar.
Categories : Date Time, PHP, Calendar | | | Phorum, MySQL, Language, UK date format, MySQL UK Date format Categories : PHP, Date Time, Strings, MySQL, Databases | | | PHP Calendar Web App Categories : PHP, Databases, MySQL, Date Time, Calendar | | | a class that uses microtime() to provide easy calculation of elapsed times
Categories : Date Time, PHP, PHP Classes | | | PHP Calendar Categories : PHP, Calendar, Date Time, Java Script, CSS | | | Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June). Categories : Calendar, Date Time, PHP | | | Date Validation using JavaScript. Intended to use it as checkdate() from PHP. Categories : Java Script, Date Time, PHP | | | PHP Round Clock - Must have Gif support to use this. Categories : PHP, Date Time, Graphics | |
| |
| | | | | jason boerner wrote :1922
most of what you're doing in the week one can be accomplished by just doing
$start_date = date('Y-m-d', strtotime("-".date('w')." days"));
$end_date = date('Y-m-d', strtotime("+".(7 - date('w'))." days"));
of course that will get you this week's start and end dates however you could easily add in some offset info into just those couple lines
| |
|
|