Forums

Date Comparison Issue - Please Help (1 post)

  1. nmallory
    Member
    Posted 6 years ago #

    I'm troubleshooting an issue in a plugin. Basically the code never recognizes when a post is current as opposed to when it it future. It always assumes it's a future post, which is wrong 99% of the time.

    Here's the code:
    # Grab post date info
    $post_year = $_POST['aa'];
    $post_month = $_POST['mm'];
    $post_day = $_POST['jj'];
    $post_hour = $_POST['hh'];
    $post_minute = $_POST['mn'];

    # Add leading zeros to month
    if ($post_month == "1") { $post_month = "01"; }
    if ($post_month == "2") { $post_month = "02"; }
    if ($post_month == "3") { $post_month = "03"; }
    if ($post_month == "4") { $post_month = "04"; }
    if ($post_month == "5") { $post_month = "05"; }
    if ($post_month == "6") { $post_month = "06"; }
    if ($post_month == "7") { $post_month = "07"; }
    if ($post_month == "8") { $post_month = "08"; }
    if ($post_month == "9") { $post_month = "09"; }

    # Date diff calculation
    $post_date = "$post_year$post_month$post_day$post_hour$post_minute";
    $curr_date = date("YmdHi");
    $date_diff = $curr_date - $post_date;

    # If post is future dated
    if ($date_diff < 0){

    For some reason $date_diff is always less than 0. I know that the $post_date value is correct because later in the code, it gets printed into a table and I see it's correct. That leaves me to suspect either that the $curr_date is incorrect or the subtraction of two date values as integers is going awry.

    Anyone who has a better understanding of php and the inner workings of WP have an idea as to what's happening?

    Thanks in advance!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.