Solved

Hide content depending on the time.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
count download link and run update query 9 54
Is this error or Notice in php error log? 6 32
WordPress Themes 10 34
Form Processing in PHP 11 30
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…
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.

930 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

12 Experts available now in Live!

Get 1:1 Help Now