note 105397 added to ref.datetime

From: Date: Mon, 15 Aug 2011 07:19:59 +0000
Subject: note 105397 added to ref.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-182486@lists.php.net to get a copy of this message
I needed a way to display an announcement on a shopping site, that would warn users that orders placed between a certain date range, would not be shipped until after a certain date. I created this simple date detection code to display the notice on certain pages. You can just copy the code and save it to a file on the site and include it anywhere you need to perform a function, or display a notice. <?php /* Code to show a message only for a certain time frame. This is a simple include file that can be used to display a message on any pages that use it. Simply us a standard include instruction to this file on the page/s where you want the notice to appear. Written by Hans Kiesouw - hans at wotworx dot com */ $start = new DateTime('30-07-2011'); // DD-MM-YYYY $endDate= new DateTime('07-08-2011'); // DD-MM-YYYY $curdate = new DateTime(date('d-m-Y')); if ($start <= $curdate && $curdate <= $endDate) { /* The message below will appear if the current date is between the start and endDate - used standards HTML to ensure that any code will not be escaped by PHP. You can use any code here to wish to execute for the date range. */ ?> <p><strong><font color="#FF0000">Please Note: Any orders placed between July 30th and August 7th will only be shipped on August 8th. We apologize for any inconvenience and thank you for your order.</font></strong></p> <?php // don't forget this last bit, it ends the if statement! } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 41.135.164.203 ---- Manual Page -- http://www.php.net/manual/en/ref.datetime.php Edit -- https://master.php.net/note/edit/105397 Del: integrated -- https://master.php.net/note/delete/105397/integrated Del: useless -- https://master.php.net/note/delete/105397/useless Del: bad code -- https://master.php.net/note/delete/105397/bad+code Del: spam -- https://master.php.net/note/delete/105397/spam Del: non-english -- https://master.php.net/note/delete/105397/non-english Del: in docs -- https://master.php.net/note/delete/105397/in+docs Del: other reasons-- https://master.php.net/note/delete/105397 Reject -- https://master.php.net/note/reject/105397 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#182486) next »