Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Hide content depending on the time.

Posted on 2013-06-07
3
Medium Priority
?
260 Views
Last Modified: 2013-06-19
Is it possible using php to display content depending on the time?

It's for a florist website. There's three options 'Delivery', 'same day delivery' and 'pick up'.

The function i'm after is for Sameday delivery, it's only available until 1pm so I want to remove that option after that time.

This obviously won't work but to show what I mean, something along the lines of......

 <?php if past 1.pm ?>Sameday option  <?php endif; ?>
0
Comment
Question by:BrighteyesDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Expert Comment

by:MrC63
ID: 39230312
Although I'm not an expert specifically with PHP synatx, we do this kind of thing in other scripting languages.  Hopefully this will

Declare a function and give it a name such as "CheckTime()".   This is written in JavaScript, so it should be easy enough to adjust it accordingly for the appropriate PHP syntax.

function CheckTime()
{
var bOK=true;
var dNow=GetDate();
if (dNow.getHour()>=13)
    dNow=false;
return bOK;
}

Then in your PHP code (again, please forgive any syntactical errors) you would simply have:

<?php if CheckNowI() ?>Sameday option  <?php endif; ?>
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39230330
Your biggest problem is determining when it is 1PM at their shop.  The time on your server will be the local time for the Server which isn't necessarily the same timezone as the shop.  But the way to use the shop time is to set the timezone before you check the time.  See here: http://php.net/manual/en/function.date-default-timezone-set.php
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39230383
Everything you need is in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

<?php // RAY_temp_brighteyesdesign.com
error_reporting(E_ALL);

// THE TIME ZONE OF THE FLOWER SHOP
date_default_timezone_set('America/Chicago');

// CHECK THE HOUR BEFORE ISSUING A MESSAGE
if (date('H') < 13) echo "Same Day Delivery is available.";

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

660 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