www.webdeveloper.com
Results 1 to 3 of 3

Thread: Generating Last Month

  1. #1
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125

    Exclamation Generating Last Month

    im Trying to grab data based on the month

    EX:

    You have Made 9 Tacos This month
    You have Made 15 Tacos Last month

    Im just having an issue generating a "Simple" start date and end date for the current month and the month before it. i need these months to be really accurate including the 28 days in febuary and leap years etc..

    i have tried playing around with the date function but have had to much trouble trying to get it to format start and end dates for each month for the grab query.

    PHP Code:
    $today getdate();

    $year $today['year'];
    $month $today['mon'];

    if (
    $today['mon'] == 2)
    {
    $this_month_start "$year-$month-1";
    $this_month_end "$year-$month-28";
    $last_mon $today['mon'];
    if (
    $last_mon == 1) {$last_mon 12;} else {$last_mon $last_mon 1;}
    $last_month_start "$year-$last_mon-1";
    $last_month_end "$year-$last_mon-31";
    }
    if (
    $today['mon'] == || $today['mon'] == || $today['mon'] == || $today['mon'] = 11)
    {
    $this_month_start "$year-$month-1";
    $this_month_end "$year-$month-30";
    $last_mon $today['mon'];
    if (
    $last_mon == 1) {$last_mon 12;} else {$last_mon $last_mon 1;}
    $last_month_start "$year-$last_mon-1";
    $last_month_end "$year-$last_mon-31";
    }
    if (
    $today['mon'] == || $today['mon'] == || $today['mon'] == || $today['mon'] == || $today['mon'] == || $today['mon'] == 10 || $today['mon'] == 12)
    {
    $this_month_start "$year-$month-1";
    $this_month_end "$year-$month-31";
    $last_mon $today['mon'];
    if (
    $last_mon == 1) {$last_mon 12;} else {$last_mon $last_mon 1;}
    if (
    $last_mon == 2) {$dd "28";} else {$dd "30";}
    $last_month_start "$year-$last_mon-1";
    $last_month_end "$year-$last_mon-$dd";

    if anyone has a better way to grab queries in a certain month that would be awesome, i also can not have a row just listing the current months name it needs to pull Date format Y-m-d

    it works, its just seems like there should be an easier way to do this and one that actually counts leap years.

    Thanks ~
    Last edited by Nvenom; 11-11-2011 at 02:53 AM.
    Albert Einstein ~ "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction."

    Things To help you on this Site

    1. Place all php code in [php] Tags
    2. Place all html code in [html] Tags
    3. Remember to mark all your Threads Resolved using thead tools at the top when your problem is solved

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Try this :
    PHP Code:
    echo "<br>Today ".date('r');
    echo 
    "<br>Month start ".date('r',mktime(000date("m") ,1date("Y")));
    echo 
    "<br>Month end ".date('r',mktime(000date("m")+10date("Y"))); 
    The last day of the month is too the źday 0╗ of the following month !

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,361
    PHP Code:
    $lastDayOfMonth cal_days_in_month(CAL_GREGORIAN$monthNum$yearNum); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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