SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php: if now is business hours echo "we are open!"

    Hello,

    I want to use php to put a note on a site saying "we are open, call now" (or whatever) if the time is between 7:30am and 4:00pm Monday to Friday.

    Any help/direction is much appreciated.
    Thanks!
    Ida

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    http://us2.php.net/manual/en/function.date.php
    PHP Code:
    if ( (int)date'N' ) < ) {
        
    $h = (int)date'G' );
        if ( 
    $h >= && $h <= 16 ) {
            print 
    'Open!';
        }

    Course I skipped the minutes on purpose. I leave that to you.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Take a look at the documentation on php.net for the date function - that has lots of information on how to get day of the week, current hour, minute, second etc.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,593
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Just remember that if you are only open for a few hours each day that you will always appear to be closed to those people who are always asleep during those hours.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't forget holidays. It reflects badly if you say you are open during a holiday and you aren't.
    MySQL v5.1.58
    PHP v5.3.6

  6. #6
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just change your message to "We are probably open" and the holiday issue will be taken care of. Most of the time.

  7. #7
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Holiday wont be an issue if he adds on the script what days his shop will be closed for say um the next year.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! Worked perfect.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •