#1
  1. A Change of Season
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,558
    Rep Power
    221

    strtotime('now') Vs strtotime(date('Y-m-d'))


    Hello;

    I wanna see if $date is today or future.

    The fact that I have to check if($date==date('Y-m-d')) is not good.

    PHP Code:
    public function is_date_in_future($date)
                  {
                    if(
    $date==date('Y-m-d'))
                      {
                        return 
    true;
                      }
                    if(
    strtotime($date) >= strtotime('now')) 
                      {
                        return 
    true;
                      }
                  } 
    Why strtotime('now') and strtotime(date('Y-m-d')) return diff things?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Location
    Lithuania
    Posts
    48
    Rep Power
    47
    No intention to insult you, but what's going on recently? For some unknown reason, your questions become more and more immature every week, and over 90% of them can be answered in seconds by using any search engine or PHP manual.

    Different things are returned because strtotime('now') returns the exact time now. In other words, it returns year, month, day, hour, minute, second. Obviously, "Y-m-d" only returns year, month and day, that's why results are different.

    Comments on this post

    • Sepodati agrees
    Do you license and update your PHP scripts?
  4. #3
  5. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,921
    Rep Power
    9646
    Using strtotime(now) is silly.

    If you want to check if a date is today then a Unix timestamp is not as helpful. Compare date strings.
  6. #4
  7. A Change of Season
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,558
    Rep Power
    221
    Originally Posted by phpmillion
    No intention to insult you, but what's going on recently? For some unknown reason, your questions become more and more immature every week, and over 90% of them can be answered in seconds by using any search engine or PHP manual.
    Hey, thanks for your reply. I am not happy these posts bother you. If you find them annoying please simply ignore them. I don't see how it could hurt anyone. I find it very useful to discuss here. The mods are watching. If I get a PM warning I take that I am doing too much and I slow down.

    Originally Posted by phpmillion
    Different things are returned because strtotime('now') returns the exact time now. In other words, it returns year, month, day, hour, minute, second. Obviously, "Y-m-d" only returns year, month and day, that's why results are different.
    My type of thinking (mind I guess) isn't really designed for coding. I am very extrovert person, always thinking waterfall way and 100% non-object oriented way of thinking.

    Because of that some simple things are difficult for me to understand.

    If we go on stage to do public speaking, I can hook the audience for a long time about almost any topic.

    I code because I have to. I noticed a while back I am better at other things.

    There are somesimple things I just can't get my head around. For example GROUP BY inMysql or GROUP CONCAT.

    I try to post as less as possible.

    Thank you

IMN logo majestic logo threadwatch logo seochat tools logo