• Hi,

    I had a developer do some changes to the Newsletter plugin for me. I needed a new variable created that returned the date 14 days from today. The idea is that when someone registers with the website, they get an autoresponse email giving them 14 days to come in to get a free sample.

    The additional change worked when I tested it, but now that the site has been deployed, I have received feedback that it isn;t working. When I look at the code that was added, the developer added the following line of code:
    ‘$text = str_replace(‘{future_date}’, date(get_option(‘date_format’), mktime(0, 0, 0, date(‘n’), date(‘j’)+14, date(‘y’))), $text);’

    The idea is that this code will allow me to add {future_date} to the newsletter form, and it will return the date + 14 days.

    Because it was initially working, but now isn’t, the most likely culpret is the date is now invalid. I did some investigation of the mktime function, and I believe that I have found the problem. In the code it is ‘returning date(‘n’)’ which is the numeric representation of the month, ‘date(‘j’) which is the numeric representation for the day, and date(‘y’) which is the numeric representation for the year.

    If I am reading the code correctly, as he has added +14 to the date(‘j’), when I run the code today (today is 20 April 2012), it is returning a value of 34 April 2012.

    Does anyone have any suggestions about how I can fix this code so that it is returning a result 14 days from today while also taking into account the end of months? I have tried to contact the developer but am not getting any responses.

    Any suggestions will be greatly appreciated.

    Thanks

    Simon

Viewing 1 replies (of 1 total)
  • Hi Simon,

    I think this should do the trick:

    $text = str_replace( '{future_date}', date( get_option( 'date_format' ), time() + ( 14 * 86400 ) ), $text );
Viewing 1 replies (of 1 total)

The topic ‘Date return code is not working’ is closed to new replies.