Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I change this code to ignore part of a date?

    I have this mod for my forum and it calls the birthdate from the database. I would like to have it not see the year. What is happening if a person puts a year in the box in their profile it makes it Dec 31st because that year is already over. There is no way to remove that box from the code according to the forum tech people. I've added the two pieces that refer to date. It already is written where it only shows the month and day in the view. Thank you to anyone that can help.


    PHP Code:
    $birthdays        get_birthdays();
        if(!
    $birthdays) {
            
    $text 'No birthdays yet';
        } else {
        
    $num count($birthdays);
        
        
    $i 1;
        
         foreach(
    $birthdays as $b) {
            
    $date explode("-"$b["user_birthday"]);
            
    $user get_user($b["user_id"]);
            
    $user_menus[] = create_user_popup($user);
            if(
    $date[2] == date('j')) {
                
    $text.= "<img src='" BASE_DIR "/birthday.gif' title=\"User's birthday today!\"/>";
                
    $dateprint '<span style=\'color:red\'><strong>TODAY!</strong></span>';
            } else {
                
    $dateprint date('F jS'mktime(000$date[1], $date[2], $date[0]));
            }
            
    $text .= user_link_code($b["user_id"], $b["user_name"]);
            
    $text .= " (" $dateprint ")";
            if(
    $num $i) {
                
    $text .= ', ';
            }
            
    $i++;
        } 
        
      } 

    PHP Code:
    /**** BEGIN  BIRTHDAYS TODAY ****/
    function get_birthdays() {
        
    $result db_query("SELECT user_id, user_name, user_birthday FROM wowbb_users
         WHERE DAYOFMONTH(user_birthday) >= DAYOFMONTH(NOW()) AND MONTH(user_birthday) = MONTH(CURRENT_DATE) AND DAYOFMONTH(user_birthday) < DAYOFMONTH(CURRENT_DATE)+7
         ORDER BY DAYOFMONTH(user_birthday) ASC;"
    );
        while(
    $row db_fetch_row($result)) {
            
    $birthdays[] = $row;
        }
        return 
    $birthdays;
    }

    /**** END BIRTHDAYS TODAY ****/ 

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Well the query seems to ignore the year on the date already. Your problem is probably happening because the birth year being entered is earlier than 1970, which is the lowest value that the mktime() function can handle in PHP.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So what is a fix for that?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I've had this function kicking around for forever... use it just like you'd use mktime().

    PHP Code:
    function MakeTime() {
       
    $objArgs func_get_args();
       
    $nCount count($objArgs);
       if (
    $nCount 7)
       {
           
    $objDate getdate();
           if (
    $nCount 1)
               
    $objArgs[] = $objDate["hours"];
           if (
    $nCount 2)
               
    $objArgs[] = $objDate["minutes"];
           if (
    $nCount 3)
               
    $objArgs[] = $objDate["seconds"];
           if (
    $nCount 4)
               
    $objArgs[] = $objDate["mon"];
           if (
    $nCount 5)
               
    $objArgs[] = $objDate["mday"];
           if (
    $nCount 6)
               
    $objArgs[] = $objDate["year"];
           if (
    $nCount 7)
               
    $objArgs[] = -1;
       }
       
    $nYear $objArgs[5];
       
    $nOffset 0;
       if (
    $nYear 1970)
       {
           if (
    $nYear 1902)
               return 
    0;
           else if (
    $nYear 1952)
           {
               
    $nOffset = -2650838400;
               
    $objArgs[5] += 84;
               
    // Apparently dates before 1942 were never DST
               
    if ($nYear 1942)
                   
    $objArgs[6] = 0;
           }
           else
           {
               
    $nOffset = -883612800;
               
    $objArgs[5] += 28;
           }
       }

       return 
    call_user_func_array("mktime"$objArgs) + $nOffset;


  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    not sure how to do that but will look into it. Thank you.

  • #6
    New Coder
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you help out an old lady and tell me what I need to do with that code??

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Put it in a PHP file and then use require() in your script to use it. Then just call the MakeTime() function in place of PHP's mktime() function.

  • #8
    New Coder
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh ok. Thank you.

  • #9
    New Coder
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok I did that and yes now if the year is there and it is before 1970 it shows the right month and day. BUT, now if they do not have the year added it does the December 31st date. It just reversed the problem. Is there no way at all to tell it to ignore the year??

  • #10
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I don't follow when you say "when they don't enter a year". I thought the tech guys from the forum you're using said the year is required? And isn't this birthday stored in a MySQL database as a DATE type value? So you've got to have a year for that value.

    To answer your question directly-- mktime() (and that custom MakeTime() function) don't require a year value (they will default to current year if it is omitted), but a DATE type value stored in a MySQL database must have a year value.

  • #11
    New Coder
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There is an option in the drop down in profile that just says year and if you choose that the system allows it. So when a member has that setting that is where the problem arises. I can't win either way, lol. i tried going in and adding the birthday in the array for required fields on registration but haven't got it to work yet and then if it does I'm not sure it will matter because the same year options like the name year will still be there. Unless I can get that out too. But then if anyone else wants to use this mod they have to go through the same hoops so really wanted to fix of some kind beside having to change 10 more things, lol

  • #12
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Just validate the year-- if it's not between 1900 and 2100 then use current year.

  • #13
    New Coder
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok


  •  

    Posting Permissions

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