0

I am printing time slots according some business hours in 30min difference to select start time of online appointment.

Am stuck on a problem, here brief explanation:

Bussiness Hours(start-end) = 10:00am - 5:00pm

Slot settings: 30min

Then slot listing will be display as:

10:00am - 10:30am - 11:00am - 11:30am - 12:00pm - 12:30pm - 01:00pm 01:30pm - 02:00pm - 2:30pm - 03:00pm - 03:30pm - 04:00pm - 04:30pm

I getting current server timezone time using hardcore $UserTimeZoneIdentifire timezone identifier variable and disabling all past time according current server timezone running time.

$UserTimeZoneIdentifire = "America/Denver";

For example:

If Customer 'ABC' current timezone time is: 12:33pm then all time slots between 10am-12:33pm will be disable and available time will be start from 12:35pm (rounding of minute in multiple of 5).

Here some code:

/**
 * If appointment date is current date then get current user's timezone time
 */

$UserTimeZoneIdentifire = "America/Denver";

if(strtotime($AppointmentDate) == strtotime(date("Y-m-d"))) {

    date_default_timezone_set($UserTimeZoneIdentifire);
    echo $Biz_start_time = $BusinessHours['Biz_start_time']; echo "--biz start time<br>";
    echo $UserCurrentTime = date("h:i A");  echo "--current server time<br>";

    echo $ServerCurMinute = substr($UserCurrentTime, 3,5);  echo "--strip minutes time<br>";
    echo $RoundOffMinute = round(($ServerCurMinute+5/2)/5)*5;   echo "--round off minutes time<br>";

    if($RoundOffMinute > 55) {
        /*
         * If minutes are greater then 55 then add 1 hour in time
         */
        $UserCurrentTime = substr_replace($UserCurrentTime, "00", 3, 2);
        $UserCurrentTime = date("h:i A", strtotime("+1 hour", strtotime($UserCurrentTime)));
    } else {
        if($RoundOffMinute <= 5) {
            $RoundOffMinute = "0".$RoundOffMinute;
        }
        $UserCurrentTime = substr_replace($UserCurrentTime, $RoundOffMinute, 3, 2);
    }
    $Biz_start_time = $UserCurrentTime;
    $Biz_end_time = $BusinessHours['Biz_end_time'];

} else {
    $Biz_start_time = "10:00am ";
    $Biz_end_time = "05:00pm";
}

Problem is, I have stored hard-coded value of my timezone identifier in a php variable. But, How could I get current server timezone identifier using php to set $UserTimeZoneIdentifire variable dynamically rather than hard coded value at any timezone?

So, any of help and other technique appreciated through you guys. Thanks.

Frank
  • 2,285
  • 7
  • 43
  • 68
  • Start using DateTime class instead of date(), strtotime(), time() etc function. – Glavić Sep 09 '13 at 13:19
  • I want timezone identifier name like **[this](http://www.php.net/manual/en/timezones.america.php)**. – Frank Sep 09 '13 at 13:24
  • I think http://stackoverflow.com/questions/4700156/php-how-to-get-the-server-time-zone will answer your question. – Marco Frost Sep 09 '13 at 13:41
  • @Marco above question giving output: `UTC` not a proper identifier name, try this on live server not on localhost. – Frank Sep 09 '13 at 13:44
  • You asked for the *server's* time zone, but it sound like you are looking for the *user's*. Are you sure they will be the same? If not, see http://stackoverflow.com/a/16526897/634824 – Matt Johnson-Pint Sep 09 '13 at 13:44
  • Its only showing "UTC" at live server **[here](http://www.funnybunnyvideos.com/appointments/)**. – Frank Sep 09 '13 at 13:46
  • For the server's time zone, see: http://stackoverflow.com/a/3498147/634824 – Matt Johnson-Pint Sep 09 '13 at 13:46
  • thanks @Matt, but same at live server `UTC`, check [here](http://www.funnybunnyvideos.com/appointments/). – Frank Sep 09 '13 at 13:50
  • What are you point us at? We can't see your code in that... – Matt Johnson-Pint Sep 09 '13 at 13:52
  • Go [there](http://www.funnybunnyvideos.com/appointments/), click on button, select today's date, service + staff, then go next. time slots appearing on second modal window. and am showing output above the time slots. – Frank Sep 09 '13 at 13:55
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/37048/discussion-between-frank-and-matt-johnson) – Frank Sep 09 '13 at 13:57

0 Answers0