Reputation: 561
Im trying to assign a variable with timezone info that will change the time of info saved in a database.
Here is my code that doesn't work:
<?php
$timeZone = "- 3600";
$date = date('His', time() $timeZone);
echo $date;
?>
But when I do this it works...
<?php
$date = date('His', time() - 3600);
echo $date;
?>
Why won't the variable work in there?
Upvotes: 0
Views: 937
Reputation: 757
If you want to convert to another timezone, there is a proper way of doing it: UTC Date/Time String to Timezone
Upvotes: 1
Reputation: 34063
It's invalid syntax. Change $timeZone
to an integer and add it to time()
.
$timeZone = -3600;
$date = date('His', time() + $timeZone);
echo $date;
Upvotes: 1
Reputation: 17598
You can't embed binary operators in a string and expect them to execute. You'll need to do something like this:
<?php
$timeZone = -3600;
$date = date('His', time() + $timeZone);
echo $date;
?>
Upvotes: 0