Avatar ·

How to get the last day of the month from a date in PHP?

Hello, colleagues! I'm new to PHP and faced a task: I need to calculate the last day of the month from a given date. For example, the user enters "2023-02-15", and I should get "2023-02-28" (or "2023-02-29" for a leap year). I tried using `date('t', $timestamp)`, but something doesn't work out — either I'm passing the date incorrectly, or I'm using the wrong function altogether. Here's my code: ```php ``` This seems to work, but I need to get the full date, not just the day of the month. Plus, if the date comes in a different format, like "15.02.2023" or "02/15/2023", everything breaks. I'm also not sure how to account for time zones — what if the server is in a different time zone, and the result is incorrect?