php time conversion from MST to Greenwich Time, with forms


Im working w/ an api and my own code ive written to allow me to submit to that api, and I am trying to create a series of forms which will allow me to schedule actions via the API.

Basically, Im located in MST time zone (Mountain standard time), and the submission is required to be in GST (greenwich mean time) - So basically it has to look like this -


=       Apr 06, 2010 15:09:02 MST (Tomorrow at 3:09, I believe.)

So anyways, I only need to schedule actions say 10 days in advance, and would like the select input to recognize the current day, and offer 10 days out worth of dates. (So, 2010-04-06. 4/6/2010, etc), but the tricky part is this. I want it to show the options in MST, but have the actual values set as the GST equivelant times.

I basically need one select menu for the date, another for time. The trouble is the conversion of the actual values, as if I select 4-6/2010, depending on the time, it may actually be a completely different day. So I attached code sample of what I have so far below, Im thinking there is probably a much more effective/ez way to do this with php because I saw there are time conversion functions, I just dont know how to use them. (i still have much to learn..)

Thanks in advance.
<select name="schedulelistingDate">
	  $day0 = mktime(0,0,0,date("m"),date("d"),date("Y"));
	  $day0option = "<option value='";
	  $day0option .= date("Y-m-d", $day0);
	  $day0option .= "'>";
	  $day0option .= "Today - ".date("Y-m-d", $day0);
	  $day0option .= "</option>";
	  echo $day0option;
	  $day1 = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
	  $day1option = "<option value='";
	  $day1option .= date("Y-m-d", $day1);
	  $day1option .= "'>";
	  $day1option .= "Tomorrow - ".date("Y-m-d", $day1);
	  $day1option .= "</option>";
          echo $day1option;
     <select name="schedulelistingTime">
        <option value="00:00:00">12:00 AM</option>
        <option value="01:00:00">1:00 AM</option>
        <option value="02:00:00">2:00 AM</option>

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This should get you started:

Check for how to format it. I am not sure what kind of format you want the GMT time to be in.

The below code will create a form that will show in MST time and then convert to GMT.

<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <select name="schedulelistingDate">
          for($i=0;$i<10;$i++) {
                $offset = $i * 24*60*60;
                $date = time()+$offset;
                $daternd = strtotime(date('Y-m-d', $date));
                echo '<option value="';
                echo $daternd;
                echo '">';
                echo date('Y-m-d', $daternd);
                echo '</option>';
     <select name="schedulelistingTime">
        for($i=0;$i<24;$i++) {
                $offset = $i * 60*60;
                echo '<option value="';
                echo $offset;
                echo '">';
                echo "$i:00 MST";
                echo '</option>';
        <input type="submit" value="Submit">

if(isset($_POST['schedulelistingDate']) && isset($_POST['schedulelistingTime'])) {
        $date = $_POST['schedulelistingDate'];
        $time = $_POST['schedulelistingTime'];
        $datetime = $date+$time;
        echo date('Y-m-d g:i A T', $datetime);       //Print MST time
        echo "<br>";
        date_default_timezone_set('GMT');           //Convert to GMT
        echo date('Y-m-d g:i A T', $datetime);       //Print GMT time
        echo "<br>";
        echo date('Y-m-dTG:i:sZ',$datetime);


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.