Results 1 to 2 of 2

Thread: Date Issue In PHP...

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Date Issue In PHP...

    Can someone explain why this is happening... here is part of the code...

    PHP Code:
    $date date('d/m/Y');
    $p explode ' 'date('m Y') ); 

    if (
    $p[0] == 1) { 
        
    $Month 12
        
    $theYear $p[1]-1


    else { 
        
    $Month $p[0]-1
        
    $theYear $p[1];


    if (
    $Month 10) {
    $theMonth '0'.$Month;
    }

    else {
    $theMonth $Month;
    }

    $monthText date("F"mktime(0,0,0,$theMonth+1,0,0)); 
    Basically from this I am pulling info out of my database about my members, this one pulls information of them logging from last month... It works fine, but I added in the query so it says 'These members logged in $monthText'... When I ran it it was saying 'March' so I had to add the +1 after $theMonth, just not sure why I need to add the +1, any ideas?

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by tomyknoker View Post
    PHP Code:
    $monthText date("F"mktime(0,0,0,$theMonth+1,0,0)); 
    By specifying the date as zero (0) - an out-of-range value - the calculated date is rolled back one day into the preceding month.

    If your main objective is to obtain the month as a string, I would have thought it would be computationally less expensive to use:

    PHP Code:
    $monthNames = array('January''February''March''April''May''June''July''August''September''October''November''December');
    $date getdate();

    $monthText $monthNames[($date['mon'] + 10) % 12]; 
    or at the very least:

    PHP Code:
    $date getDate();

    $monthText date('F'mktime(000$date['mon'] - 1)); 
    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •