Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member Noteleklabs's Avatar
    Join Date
    Jun 2012
    Location
    NC
    Posts
    217
    Member #
    31890
    Liked
    28 times

    Exclamation Comparing Custom Timestamps

    Hullo!
    I am currently working on a system where I have to check if a certain timestamp is within a certain number of hours (this is also a variable) from now. I have no issues doing this normally, but using the method that I am, If its 1 am, and I ask for all entries from 4 hours ago, I'll get back an error for an invalid timestamp. Any help?
    Hey you! Go make something!

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    First, you'll want to nail-down a timezone.
    Your website uses your server time, and you might not be living near your server.

    Everyone using your site will be using your timezone. But remember people in Australia, for example, are like 15 hours ahead of you. So you have to reference everything from one timezone. Let's say you have a coupon that expires at midnight your time. Someone in Australia will be perplexed that it expired too early. For them, it should still be valid, but it's not because they are 15 hours ahead of you.

    So what do you mean by all entries 4 hours ago? When you visit your site, or when Aussie Arnold visits your site?

    <?php
    date_default_timezone_set('America/New_York');

    You said a "certain timestamp" ... what format is it in? UNIX timestamp, or a 'human-readable' timestamp?

    This would be a UNIX timestamp ...

    $now=time();

    That gives you a UNIX timestamp, an integer like this: 1410468053
    Last edited by mlseim; Sep 11th, 2014 at 02:46 PM.


  4. #3
    Senior Member Noteleklabs's Avatar
    Join Date
    Jun 2012
    Location
    NC
    Posts
    217
    Member #
    31890
    Liked
    28 times
    Woops, forgot to close this thread, I found a waaaay simpler solution, using the strtotime(), I could just compare strtotime($now) <= strtotime("-4 hours") and get a much simpler result. Just had to use another function to reformat timestamps to a standardised format.

    I do however appreciate your speedy and simple solution.
    Hey you! Go make something!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:10 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com