Solved

Hide content depending on the time.

Posted on 2013-06-07
3
253 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 82

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 108

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now