WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP Date Range by week and by month
Categories : PHP, Date Time Click here to Update Your Picture
Warren Gutierrez
Date : Nov 17th 2007
Grade : 4 of 5 (graded 5 times)
Viewed : 31385
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Warren Gutierrez
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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