[Webinar] Streamline your web hosting managementRegister Today


php time conversion from MST to Greenwich Time, with forms

Posted on 2010-04-05
Medium Priority
Last Modified: 2013-11-10

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

Question by:lexusgs430
1 Comment

Accepted Solution

Enclavet earned 2000 total points
ID: 29871623
This should get you started:

Check http://php.net/manual/en/function.date.php 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);


Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question