PHP subtract month gives me wrong values [duplicate] - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Thursday, May 11, 2023

PHP subtract month gives me wrong values [duplicate]

one dumb question!

I'm trying to develop one code who is able to subtract one month from one specific date but i'm facing an issue and i don't know how i can't solve it, the issue is:

If given date was 2023-05-31 and i subtract one month, instead of given me the 2023-04-30, the code shows 2023-05-01.

I just want to know how i can solve it without any workaround, because if i input one date 2023-05-28 the code must showned me 2023-04-28, any ideas?

My code below:

$date = '2023-05-31';
echo date('Y-m-d', strtotime($date . ' - 1 months')); // 2023-05-01

Thanks!



source https://stackoverflow.com/questions/76221456/php-subtract-month-gives-me-wrong-values

No comments:

Post a Comment