Brandrally
Brandrally

Reputation: 849

PHP > Set Default Timezone

We want to set the timezone up as a variable in PHP to account for different timezones / daylight savings.

Our code works perfectly when hard coded:

date_default_timezone_set('Australia/Brisbane');

But when we add a variable it dies. I am not sure why.

$setzone = "Australia/Brisbane";
date_default_timezone_set('".$setzone."');

Upvotes: 1

Views: 333

Answers (2)

Indrajeet Singh
Indrajeet Singh

Reputation: 2989

Try this code:

$setzone = "Australia/Brisbane";
date_default_timezone_set("$setzone");

Upvotes: 0

Girish
Girish

Reputation: 12127

if you will add quote then variable behaving as string for instance

$setzone = "Australia/Brisbane";
echo '".$setzone."';

Output :

".$string." //output as string not a variable value

So you need to remove quote when passing string into variable

date_default_timezone_set('".$setzone."');

to

date_default_timezone_set($setzone);

Upvotes: 6

Related Questions