1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php date error help

Discussion in 'PHP' started by fadetoblack22, Jan 14, 2019.

  1. #1
    I'm getting this for my site and it's not loading:

    PHP Fatal error: Cannot redeclare date_add() in /home/footyall/public_html/include/functions.php on line 1882

    Any ideas of how to fix it?
     
    Solved! View solution.
    fadetoblack22, Jan 14, 2019 IP
  2. Fiverscripts

    Fiverscripts Moderator Staff

    Messages:
    1,839
    Likes Received:
    42
    Best Answers:
    1
    Trophy Points:
    370
    #2
    as the error says.. the is already a built-in function named date_add you can redeclare it / replace with yours.. would help if you shared the code but thats exactly as its telling you..

    Added info for the function: http://php.net/manual/en/function.date-add.php
     
    Fiverscripts, Jan 14, 2019 IP
  3. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #3
    fadetoblack22, Jan 14, 2019 IP
  4. Fiverscripts

    Fiverscripts Moderator Staff

    Messages:
    1,839
    Likes Received:
    42
    Best Answers:
    1
    Trophy Points:
    370
    #4
    Rename this function:

    function date_add($timestamp, $months)
    {
       $d       = getdate ($timestamp);
       $mon     = $months % 12;
       $years   = $months / 12;
       $mytime  = mktime ($d['hours'], $d['minutes'], $d['seconds'], $d['mon'] + $mon, 1, $d['year'] + $years);
       $days    = min ($d['mday'], date ('t', $mytime));
       $mytime += ($days -1) * 86400;
       return $mytime;
    }
    Code (markup):
    rename: date_add bit..

    Note you will need to find everywhere you are actually using this and also change it.. i.e if you are calling that function elsewhere you need to rename it the same..

    thanks
     
    Fiverscripts, Jan 14, 2019 IP
  5. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Sorry, I don't understand. What would I rename it to?
     
    fadetoblack22, Jan 14, 2019 IP
  6. Fiverscripts

    Fiverscripts Moderator Staff

    Messages:
    1,839
    Likes Received:
    42
    Best Answers:
    1
    Trophy Points:
    370
    #6
    e.g
    function mydate_addfunction($timestamp, $months)
     
    Fiverscripts, Jan 14, 2019 IP
  7. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #7
    Thanks, so just anything?

    What I don't get is why the previous one stopped working. Is there a reason why?
     
    fadetoblack22, Jan 14, 2019 IP
  8. #8
    yeah.. as i mentioned earlier

    "Added info for the function: http://php.net/manual/en/function.date-add.php"

    the is already a built in function called it as above.. thats why

    Note: feel free to push "best answer" if you found my replies helpful :)
     
    Fiverscripts, Jan 14, 2019 IP
  9. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #9

    Let me try and understand...php has an added function now which is conflicting with it. Is that right?
     
    fadetoblack22, Jan 14, 2019 IP
  10. Fiverscripts

    Fiverscripts Moderator Staff

    Messages:
    1,839
    Likes Received:
    42
    Best Answers:
    1
    Trophy Points:
    370
    #10
    i actually think this function has been around for a while did your server possibly update php versions recently?
     
    Fiverscripts, Jan 14, 2019 IP
  11. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #11
    Yeah, the site was offline for a while and I re-uploaded it.

    Any idea how I can search for all instances of the function?
     
    fadetoblack22, Jan 14, 2019 IP
  12. Fiverscripts

    Fiverscripts Moderator Staff

    Messages:
    1,839
    Likes Received:
    42
    Best Answers:
    1
    Trophy Points:
    370
    #12
    i would use agent ransack (google it.. freeware for none commercial use) search for instances containing that specific function
     
    Fiverscripts, Jan 14, 2019 IP
    fadetoblack22 likes this.
  13. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #13
    Thank you!
     
    fadetoblack22, Jan 15, 2019 IP
    Fiverscripts likes this.
  14. Alice Egger

    Alice Egger Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #14
    Hi,
    You can use date("Y/M/D") function. I works.
     
    Alice Egger, Jan 18, 2019 IP
  15. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #15
    Do you mean instead of DMY?
     
    fadetoblack22, Jan 18, 2019 IP
  16. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #16
    For future, always use "camelCase" for your own functions. That word "camelCase" is written in camel case.
    That way your written functions will not conflict with php's builtin functions.

    Also consider using if(!function_exists("functionName")){ } for every function you write.
     
    JEET, Mar 29, 2019 IP