Solved

Hide content depending on the time.

Posted on 2013-06-07
3
255 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
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 109

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

773 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