Solved

Hide content depending on the time.

Posted on 2013-06-07
3
257 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 83

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 110

Accepted Solution

by:
Ray Paseur earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delete image(s) associated with record(s) 16 46
XML loaded in a form with dropdown 6 57
how can I see the time difference in only seconds? 4 40
Php variable to be sent back 3 35
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

710 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