Can someone check my logic just so I know for sure that I'm doing this right?

A student goes out to my page to make some last minute changes knowing that the cutoff is drawing near. In this case, it's December 4th. She has to have all of her updates done before the clock strikes 12:00 AM, December 5th.

The code that I have written which defines that dynamic is this:

if($marketing_end_four<=$today AND $mk_four_close=="0000-00-00")
//empty the system of all entries that have been made up to midnite the day the marketing period ends.

$marketing_end_four in this case is 2013-12-04. My "<-," in my mind, means that all the entries that have been made up to 11:59 PM on the 4th will be processed.

Before I had the code set up so it read "if($marketing_period_four<$ what was happening is that you couldn't make any changes on the day the marketing period ended. But with the "<=," now I've got things where the user can change things right up to 12:00 AM on the fifth.

brucegustPHP DeveloperAsked:
Who is Participating?
Ray PaseurConnect With a Mentor Commented:
Philosophically accurate, yes.  

Timezones are standardized and named, and the difference between US East Coast ("America/New_York") and US West Coast ("America/Los_Angeles") is three hours.

This statement will create an integer value of 1997.  You probably want a quoted literal string.
Matthew KellyConnect With a Mentor Commented:
Just to make sure... both $marketing_end_four and $today are date variables and not strings correct?

If $today is set to something like $today = time(); it will have both date and current hours in it while the end_four variable which was just set to 2013-12-04 will really be "2013-12-04 00:00:00.000" because you didn't pass any hours/minutes/seconds to it.

So you need to add the hours/minutes to marketing_end_four i.e make it "2013-12-04 23:59:59.999" or simply do

The less than or equal still won't work because you will be comparing "2013-12-04 00:00:00.000" <= "2013-12-04 09:54:35.000" which will still be false.
brucegustPHP DeveloperAuthor Commented:
Alright, Matt! First off all, I appreciate your time so thanks for getting back with me.

I've got $today set to $today=date("Y-m-d") so there's no "timeframe" involved at all, I'm just looking at, from what you're suggesting: if(2013-12-04 <= 2013-12-04)...

So, maybe that's not enough to accommodate the fact that these folks need up to midnite to make their changes, yes?

If that's the case, what do I need to do?

From what I can gather, based on what you've said up top, is that even with the hours and seconds added, I'm still going to come up short.

So what are my options? How do I need to accommodate the "the bell strikes at midnight" thing?
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

käµfm³d 👽Commented:
Why not set a variable to hold December 5th, at midnight and then compare that the current date is less than (not less than or equal) that variable?

Pseudo-Code (I don't fully understand PHP's date/time structures, so this code is just for example)
$cutoff = "2013-12-04 00:00:00";
$now = get_date();

if ($now < $cutoff)
    // user can still do stuff
    // deny changes

Open in new window

Matthew KellyCommented:
Bruce, if neither the $today nor $end_marketing_four have time (both 00:00:00.000) then less then or equal will work. You can confirm by outputting both vales and ensuring houtd minutes seconds are all zeros.

For future code maintainability though you will want to set the end to 23 59 59 999 in case the $today value is changed to date and time.
Ray PaseurCommented:

PHP time() does not include milliseconds.  PHP's interpretation of "now" includes time.  Its interpretation of "today" does not include time, and implies a time of 00:00:00.

The timezone, either explicitly set or implied by a configuration setting, is in play when you try to establish a cutoff.  If the cutoff is midnight, this begs the question, "Midnight where?" since midnight in my time zone (Chicago) happens two hours before midnight in Seattle.  However the value of time() will be the same worldwide.

The MySQL data base engine can have a different timezone setting from the PHP engine; they are completely independent and your programming must account for this.

I'll try to give you a code sample you can test with.
Ray PaseurCommented:
See if this helps sort it out...

<?php // RAY_temp_brucegust.php
echo '<pre>';

$now = date('c');
$inp = !empty($_GET['t']) ? strtotime($_GET['t']) : FALSE;
if ($inp)
    $inp = date('c', $inp);


$form = <<<EOD
<input name="t" /><input type="submit" value="Go!" />

echo $form;

Open in new window

HTH, ~Ray
brucegustPHP DeveloperAuthor Commented:
Ray, as always, I bow before your coding glory...!

Here's my question: When I built this thing, I didn't factor in time at all, just date. So now that there's a timeframe needing to be considered, what I'm hearing you say resonates in a couple of ways.

First of all, I need to establish a benchmark. If someone the West Coast goes to insert a value, thinking they've got an hour before the gates close, if my server is sitting in Tennessee, they're going to be in for a surprise. So I've got to establish the timezone on my server and ensure that's reflected throughout the app so no one is caught off guard.

As far as my initial dilemma, provided I establish the date on my app so it's founded on the Central Time Zone, is my code sufficient to ensure that if the date that they're entering their info (which is simply 2013-12-04 as opposed to a detailed timestamp) is going to accomplish what I'm trying to accommodate as far as keeping the gates open till 12:00 AM on the fifth?

In other words, what assumptions are made by PHP when it sees 2013-12-04? Does it automatically assume 12:00 AM or is there an assumed timeframe that could render my code pointless should they attempt to make any changes the day that the marketing period closes?

I should also add that when one of my users adds info, the date of that interaction is recorded as 2013-12-04 and not as a timestamp, so there's no specific "times" involved at all with the way I've coded things.

So, having said all that, do I need to just add a date_default_timezone_set("America/Chicago"); somewhere and I'll be OK, or what do I need to do based on what I currently have in place to make sure that if the marketing period closes on the fourth, the system doesn't do anything before 12:00 AM on the fifth?
Ray PaseurConnect With a Mentor Commented:
coding glory

As I see it there are a few moving parts to the question.  Let's take the human interface first.  Anything you do should be done with transparency, so I would have a prominent statement on the web site that says "Marketing Period Closes at Midnight Central Time on December 4th"  The statement might be accompanied with a color indicator like a traffic light showing green, then yellow as the deadline approaches, then red ("Marketing Period Has Closed") when the date changes from the 4th to the 5th and the period is closed.

The machine parts are simpler.  If the only information you're tracking is the date, and the period ends at midnight on your server's time, you can simply ignore the time of day.  You want to use date_default_timezone_set() or set the timezone in your configuration since it will be part of the implied contract with your clients.

I expect you do not need to think about MySQL's time zone.  You can handle everything in PHP.

Does that make sense for your requirements?
brucegustPHP DeveloperAuthor Commented:
I believe so. Let me explain things back to you just so I can sound intelligent when I speak to my client.

The code that I have in place is fundamentally sufficient as far as the allowing for a person to be making edits and adjustments up to midnite on the fourth given the current configuration of my code:


//user can do stuff
//doors are closed

Ideally, best practices would dictate that I code this in the context of a timestamp. But, while I didn't necessarily plan it this way, what I have works because PHP is going to assume that a plain date is going to include the timeframe between 12:00 AM and 11:59 PM.

The reason some of my users might've run into an issue is that if they're making edits at 11:05 PM on the West Coast, if my server is sitting on the East Coast, the time according to the system is 12:05 AM and that is where my problem is.

By establishing the timeframe on my server, regardless of where the service itself resides, I can maintain the consistency I need for all my users regardless of where they're at.

Is that accurate?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.