Skip to content
Advertisement

PHP, MySQL date calculations

I’m trying to add a number of weeks to date, both will be taken from a database, I successfully fetch both needed but I can’t figure out how to make the calculations. So far I tried with “strtotime” but it gave me some weird results

JavaScript

How do I do this the right way? The desired result should be printing the $recoredDate + $weeks.

Advertisement

Answer

Try with

JavaScript

Without second parameter (which is also timestamp), strtotime will return current timestamp with, in your example, added x weeks. If you want to add weeks to a date, and then use date in some format, first you must add weeks to a timestamp value of a date, and then format it with date() function.

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