Skip to content
Advertisement

Increment variable date in PHP

I am grabbing the post published date (WordPress) and trying to add 2 days to it to create a post expiry date. But I am throwing the following error:

Notice: A non well formed numeric value encountered

Here is my code:

JavaScript

Can anyone point out my error here please?

Advertisement

Answer

When using slashes to separate your date parts PHP assume month/day/year format. You are using day/month/year format which can result in dates that not possible (i.e. 30/12/2021).

When manipulating date values either use Unix timestamps or month/day/year format:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement