php current_date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tao
    New Member
    • Jul 2007
    • 3

    php current_date

    Hi, I meet some problem in debugging php files.

    this is the one running smoothly

    [code=php]$query = "select account.id as account_id from account
    where (date(creationd ate)=date(curre nt_date-interval '1 days') or account.status= 'DELETED');[/code]

    but when I changed the condition to:
    [code=php]if ($result_array['creationdate'] != date(current_da te-interval '1 days'))
    {
    //do something
    }[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    there is parse error for '1 days'

    parse error, unexpected T_CONSTANT_ENCA PSED_STRING


    can anyone throw some idea??

    Thank you
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, tao. Welcome to TSDN!

    PHP works a little differently than MySQL. Try this instead:
    [code=php]
    if ($result_array['creationdate'] != date('+1 day'))
    [/code]

    Comment

    • tao
      New Member
      • Jul 2007
      • 3

      #3
      still doesn't work...

      can someone help again?

      Originally posted by pbmods
      Heya, tao. Welcome to TSDN!

      PHP works a little differently than MySQL. Try this instead:
      [code=php]
      if ($result_array['creationdate'] != date('+1 day'))
      [/code]

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        You are trying to compare a DATE field to a string [PHP]if ($result_array['creationdate'] != date(current_da te-interval '1 days'))[/PHP] At the same time you are trying to pass a mathematical result and a string with no concatenation to date().
        What is it you are trying to achive? The following is not very helpful
        still doesn't work...

        Comment

        • tao
          New Member
          • Jul 2007
          • 3

          #5
          the data type of current_date is DATE, so I am not comparing a DATE to a string.....

          I am trying to get the value of yesterday by (current_date-interval '1 days') in php.

          Originally posted by code green
          You are trying to compare a DATE field to a string [PHP]if ($result_array['creationdate'] != date(current_da te-interval '1 days'))[/PHP] At the same time you are trying to pass a mathematical result and a string with no concatenation to date().
          What is it you are trying to achive? The following is not very helpful

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, tao.

            Originally posted by tao
            the data type of current_date is DATE, so I am not comparing a DATE to a string.....

            I am trying to get the value of yesterday by (current_date-interval '1 days') in php.
            MySQL may store the value as a date, but it fetches it as a string. To compare it to another date, you must first convert it into a timestamp by using strtotime().

            To get yesterday's date, you will also need to use strtotime():
            [code=php]
            $yesterday = strtotime('-1 day');
            [/code]

            Comment

            Working...