Hi all,

How do I convert local GMT time to EST? Here's my code...


$file_date = date("Y-m-d G:i" ,strtotime($file['file_date']));

Thanks.

    well, you'd have to specify the timezones somehow (an array would work 😉 ) and then explicitly do the conversion:

    <?php
    $tz = array( 'GMT' => '0',
                       'EST' => '-5',
                       'PST' => '-8'
                      );
    // I only know the US ones :(
    
    $zone = 'EST';
    // The zone you want the time for
    
    $file_data = date('Y-m-d G:i', strtotime(($file['file_date']+$tz[$zone])));
    
    ?>

    Easy as pie right?

      why is there no value set for $zone?

      	     $tz = array( 'GMT' => '0',
                         'EST' => '-5',
                         'PST' => '-8');
      			 $zone = 'EST';
      			 echo $zone;
      	 		 // Process Date **********************************
      			 $file_date = date("Y-m-d G:ia" ,strtotime($file['file_date']+$tz[$zone]));

        My date/time is returned from SQL DB as ... 5 May 2006 10:35

          why is there no value set for $zone?

          THere is one... it's right here:

          $zone = 'EST'; 

          (look after the $tz array)

          Oh... well your time/datestamp is a format that I was unsuspecting.... do this then....
          In the query, grab it as a UNIX_TIMESTAMP(file_date) and then do this:

          $tz = array('GMT' => '0',
          'EST' => '-5',
          'PST' => '-8'
          );
          
          $hour = 60*60; // 3600 seconds / hour
          
          // Set the timezone:
          $zone = 'EST';
          
          $file_date = date('Y-m-d G:i a', ($file['file_date']+($tz[$zone]*$hour)));
          echo $file_date;
          ?>

          That should get you somewhere....

            Write a Reply...