Display message or button dependent on datetime

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FishWagon
Forum Newbie
Posts: 2
Joined: Mon Oct 19, 2009 8:38 pm

Display message or button dependent on datetime

Post by FishWagon »

Hello everyone,

I have a form that adds an item to a shopping cart. The user would like her items available only during certain parts of the day as she delivers the items same day, and only certain items are available on certain days.

So her shopping page looks something like this (each item is it's own form, and the buy now button submits the form):

Monday: Item 1 <buy now button>
Tuesday: Item 2 <buy now button>
Wednesday: Item 3 <buy now button>

and so on

Let's say the cutoff time is 10am

On Sunday, you will see all items with the buy now buttons. On Monday, if it's before 10am, you will see everything.

On Monday at 10:01am you will see

Monday: Item 1 "Sorry this is no longer available to order today"
Tuesday: Item 2 <buy now button>
Wednesday: Item 3 <buy now button>

So I need to either display the buy now button (which submits the form), or show a message. Which one is shown is based on the current date and time.

Any ideas??

Thanks to all and have a great day.

Rich
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Display message or button dependent on datetime

Post by requinix »

Compare date("Hi") with the cutoff time.

Code: Select all

if (date("Hi") < "1000") {
    // good
} else {
    // too late
}
Remember:
1. Use a 24-hour clock. 5:30pm is "1730".
2. Times before 10am need a leading zero - so it's four digits. 5:30am is "0530".

You can compromise on those requirements by using more complicated code.
FishWagon
Forum Newbie
Posts: 2
Joined: Mon Oct 19, 2009 8:38 pm

Re: Display message or button dependent on datetime

Post by FishWagon »

Thanks, don't know why I didn't think of that. I guess I was over complicating things in my mind...haha

Got it, thank you very much.

Rich
Post Reply