Results 1 to 12 of 12

Thread: [Resolved] Date Comparison Problems

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [Resolved] Date Comparison Problems

    I'm having a problem comparing dates. I've tried the following two:

    Code:
    //tried this:
    if ($comic['released'] <= date('Y-m-d')) {
        $date = "Now!";
    } else {
        $date = date('F jS, Y', strtotime($comic['release'])) . ".";
    }
    
    //and this:
    if (date('Y-m-d', strtotime($comic['released'])) <= date('Y-m-d')) {
        $date = "Now!";
    } else {
        $date = date('F jS, Y', strtotime($comic['release'])) . ".";
    }
    $comic['released'] is a date format in MySQL.

    No matter what, it always prints "Now!"

    Where am I going wrong?
    Last edited by The Hobo; Jan 30th, 2003 at 12:58 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    make date a variable.

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    make date a variable.
    What...?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    PHP Code:
    $newdate date("Y-m-d"); 


    try to stay away form ' in the variables. I found out the last couple of days that is is totally different then using "

    so they are different

    $some['variable']
    $some["variabel"]

    one will be correct as the other one will be empty.

  5. #5

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    PHP Code:
    $newdate date("Y-m-d"); 
    What difference is that going to make?

    Originally posted by phpman
    try to stay away form ' in the variables. I found out the last couple of days that is is totally different then using "

    so they are different

    $some['variable']
    $some["variabel"]

    one will be correct as the other one will be empty.
    I've never had a problem using single quotes before.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    No luck:

    Code:
    $today = date('Y-m-d');
    $released = date('Y-m-d', strtotime($comic['released']));
    
    if ($released <= $today) {
        $date = "Now!";
    } else {
        $date = date('F jS, Y', strtotime($comic['release'])) . ".";
    }
    Am I setting up the comparison wrong?

    I want to say is $released less than or equal to $today. That's right, isn't it?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    maybe it would be easier to compare using a unix timestamp, where its just a straight number.

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Even when I compare them as timestamps, it doesn't work.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Damn, I just found my problem...

    Code:
    $today = date('Y-m-d');
    $released = date('Y-m-d', strtotime($comic['released']));
    
    if ($released <= $today) {
        $date = "Now!";
    } else {
        $date = date('F jS, Y', strtotime($comic['release'])) . ".";
    }
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by The Hobo
    No luck:

    Code:
    $today = date('Y-m-d');
    $released = date('Y-m-d', strtotime($comic['released']));
    
    if ($released <= $today) {
        $date = "Now!";
    } else {
        $date = date('F jS, Y', strtotime($comic['release'])) . ".";
    }
    Am I setting up the comparison wrong?

    I want to say is $released less than or equal to $today. That's right, isn't it?
    yeah that is correct. I have had simialar problems and making the date as a variable makes it simplified and the problem went away.

    what is $comic['released'] - the value of it?

  11. #11
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    hehe I hate those with a passion

  12. #12

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman

    what is $comic['released'] - the value of it?
    It was supposed to be $comic['release'] I make dumbass mistakes like this all the time, and it takes me hours to figure it out.

    So this is the code I'm using now:

    Code:
    if (strtotime($comic["release"]) <= strtotime("now")) {
        $date = "Now!";
    } else {
        $date = date('F jS, Y', strtotime($comic['release'])) . ".";
    }
    *sighs* Thanks for all your help.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width