-2

This is how I get the date time of a city,

$date = new DateTime('now', new DateTimeZone('Asia/Bangkok'));

instead that need to get it from variables, I tried the below code but it not successful.

$type     = 'Asia';       
$type1     = 'Bangkok';

$date = new DateTime('now', new DateTimeZone('$type/$type1'));

Please help me with this.

Son Truong
  • 12,343
  • 5
  • 28
  • 54
Yasitha
  • 15
  • 6

1 Answers1

-1

You need to use double quotes

  $date = new DateTime('now', new DateTimeZone("$type/$type1"));

for an explanation, I will refer you to this question explaining the difference between '' and "" in PHP.

What is the difference between single-quoted and double-quoted strings in PHP?

mpm
  • 19,860
  • 7
  • 48
  • 55