Results 1 to 10 of 10

Thread: [RESOLVED] If today, check if after 1 PM EST

  1. #1
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 00
    Location
    Rochester, NY
    Posts
    9,334

    Resolved [RESOLVED] If today, check if after 1 PM EST

    Here's my dilemma. my wifes flower shop has a delivery cut off at 1 PM EST. I need to check if the date is today... and if its after 1.

    I can figure out how to check the time, because the person ordering could be in another time zone.

    so, the delivery date is passed through post to a payment page as $delivery_date (php). Now, the user could start the order at noon, but wait an hour + before finishing and hitting submit on the payment page. So, how do i check the date ($delivery_date) and then, if its today, check if its after 1 PM EST. if so, dont submit and alert them.

    I would assume JS would be best since i can do it on the form submit for validation....

    i have code that stops the user from selecting today if after one, when they are at the delivery info page.

    i THINK this is correct for taking into account the timezone...

    Code:
    var offset = -4.0;
    				    var clientDate = new Date();
    				    var utc = clientDate.getTime() + (clientDate.getTimezoneOffset() * 60000);
    				    var d = new Date(utc + (3600000*offset));
    	          if (dayOfWeek == 6 && d.getHours() > 12 || d.getHours() > 13) {
    etc
    etc
    (note: on saturday, if after 12 EST then no good)

    so how do i do it if the date value (ex: 7/30/2012) is stored in a POST or in a PHP variable.

    thanks!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: If today, check if after 1 PM EST

    This one is a good javascript library for date manipulation:http://code.google.com/p/datejs/

    And if you want to use the date from a PHP variable, just echo it in the javascript.

    Example:
    PHP Code:
    <?php
      $msg 
    'hi';
    ?>
    <html>
      <body>
        <script>
          var m = "<?php echo $msg?>";
          alert(m);
        </script>
      </body>
    </html>

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  3. #3
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    Re: If today, check if after 1 PM EST

    EST is UTC-4, therefore 12pm/1pm EST is 4pm/5pm UTC, therefore:
    Code:
    var now = new Date();
    if (now.getUTCHours() >= (now.getUTCDay() == 6 ? 16 : 17))
    {
      // stop
    }
    Of course, this isn't taking into account daylight savings.

    You must validate also validate the order time on the server side.
    Last edited by penagate; Jul 25th, 2012 at 11:15 PM. Reason: elementary arithmetic error

  4. #4
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 00
    Location
    Rochester, NY
    Posts
    9,334

    Re: If today, check if after 1 PM EST

    Hey Pen!

    ok, can I safely assume DST is a pain?
    how this look?
    Code:
    function validateDelTime()
    {
    	var delDate = new Date(Date.parse("<?php echo $delivery_date ?>","MM/dd/yyyy"));
    	var dt = new Date();
    	var now = new Date();
    	
    	// check if today
    	if (delDate.setHours(0,0,0,0) == dt.setHours(0,0,0,0)) 
    	{
    		// check if after 12/1 EST
    		if (now.getUTCHours() >= (now.getUTCDay() == 6 ? 16 : 17))
    		{
    			var ct = (now.getUTCDay() == 6 ? 12 : 1);
    			alert("The delivery cutoff time for today is " + ct + ":00 PM EST. Please go back select the next available day or call the store directly.");
    			return true;
    		}
    		return false;
    	}
    }

    @akhileshbc - thanks, but i dont want another whole file for a simple check.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    Re: If today, check if after 1 PM EST

    Why are you checking the date in JavaScript after it's already been posted to the server?
    Shouldn't you check the delivery date before submitting the form?

  6. #6
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 00
    Location
    Rochester, NY
    Posts
    9,334

    Re: If today, check if after 1 PM EST

    the first step is the user fills out the delivery information... address, names, date they would like it delivered. Then click submit. The Next step is payment..

    If they start it before 1:00, but then wait till 1:30 or 2 or whatever, to finish and submit... I want to make sure that its not past 1:00 when they actually complete the order. I dont want an order to squeeze through when its too late. So, the date is not really posted.. its just passed from part one of checkout to part 2.. get it?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    Re: If today, check if after 1 PM EST

    OK, I get it... presumably then you want to do the validation at both stages (and on the server side as well).

  8. #8
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 00
    Location
    Rochester, NY
    Posts
    9,334

    Re: If today, check if after 1 PM EST

    yes...

    the calendar picker checks the time every time its opened, so you cant pick today if its after one.
    then i want to do the same check (posted above) on both the delivery info page and the payment page.

    so does that code look right? (I hate how it just breaks if you get it wrong lol)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    Re: If today, check if after 1 PM EST

    Looks fine. Don't you have a debugger?

  10. #10
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 00
    Location
    Rochester, NY
    Posts
    9,334

    Re: If today, check if after 1 PM EST

    seems like this might be it...

    i hit a snag with getUTCHours because once it hits 1 am it was less than 16 and the day became available again. so i THINK i have it right now
    Code:
    function validateDelTime()
    {
    	var fld=document.forms["deliveryform"]["delivery_date"];
    	var delDate = new Date(Date.parse(fld.value,"MM/dd/yyyy"));//
    	var dt = new Date();
    	var now = new Date();
    	
    	// check if today
    	if (delDate.setHours(0,0,0,0) == dt.setHours(0,0,0,0)) 
    	{
    		utc = now.getTime() + (now.getTimezoneOffset() * 60000);
    		nd = new Date(utc + (3600000*-4));
    		// check if after 12/1 EST
    		if (nd.getHours() >= (nd.getDay() == 6 ? 12 : 1))
    		{
    			var ct = (now.getDay() == 6 ? 12 : 1);
    			alert("The delivery cutoff time for today is " + ct + ":00 PM EST. Please go back select the next available day or call the store directly.");
    			return true;
    		}
    		return false;
    	}
    }
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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