Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To change the timezone of a variable $date in PHP, you can use the datedefaulttimezoneset() function. For example, if you want to set the timezone to "America/NewYork", you can use the following code:

$date = "2022-03-01 12:00:00";  // current date and time
date_default_timezone_set('America/New_York'); // set the timezone to New York
$new_date = date("Y-m-d H:i:s", strtotime($date)); // convert the date and time to the new timezone

This will set the timezone to "America/NewYork" and convert the date and time stored in $date to that timezone, and store it in the variable $newdate. You can replace "America/New_York" with the desired timezone for your application.