Web Analytics Made Easy -
StatCounter compare two different date format - CodingForum

Announcement

Collapse
No announcement yet.

compare two different date format

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • compare two different date format

    Take a look into the following select statements:
    Select Date_Format(TS_Post_DT,"on %e/%c/%Y at %T"), UI_Login FROM Topic_Start LEFT JOIN User_Info ON TS_UI_ID=UI_ID WHERE TS_D_ID='.$row['D_ID'] .' LIMIT 1'


    SELECT Date_Format(User_Option.UO_Last_Login,'on %e/%c/%Y at %T') FROM User_Option LEFT JOIN User_Info ON User_Option.UA_UI_ID=User_Info.UI_ID WHERE User_Option.UA_UI_ID=".$_SESSION['id'];

    I want to compare the two Date_Format fields.....how can i do this thing?

    How i can print the row Date_Format(User_Option.UO_Last_Login,'on %e/%c/%Y at %T') after the execution of the query......I used the row[0]

  • #2
    Re: compare two different date format

    Originally posted by alaios
    I want to compare the two Date_Format fields.....how can i do this thing?
    Do you mean unside your server side script ? Maybe post the format it is returned in so we don't need to look it up + the server side scriptinglanguage that you use.
    Originally posted by alaios
    How i can print the row Date_Format(User_Option.UO_Last_Login,'on %e/%c/%Y at %T') after the execution of the query......I used the row[0]
    Is this a question or just some info?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      axa

      This select produce the date in the following format
      on 26/2/2000 at 04:48:51

      Yes it is a question.....
      How i can print the row Date_Format(User_Option.UO_Last_Login,'on %e/%c/%Y at %T') after the execution of the query......I used the row[0]

      I need the alternative way.......row['User_Option.UO_Last_Login']
      doesn't work to me

      Comment


      • #4
        Re: axa

        Originally posted by alaios
        How i can print the row Date_Format(User_Option.UO_Last_Login,'on %e/%c/%Y at %T') after the execution of the query......I used the row[0]

        I need the alternative way.......row['User_Option.UO_Last_Login']
        doesn't work to me
        I see. You want to get it as an associative array.
        Use an alias for that field inside the sql-stataement. Like

        SELECT Date_Format(User_Option.UO_Last_Login,'on %e/%c/%Y at %T') as formateddate FROM User_Option LEFT JOIN User_Info ON User_Option.UA_UI_ID=User_Info.UI_ID WHERE User_Option.UA_UI_ID=".$_SESSION['id'];

        and then you can print it with
        echo $row['formateddate'];
        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

        Comment


        • #5
          and the compare?

          So, i create two aliases one for each select.
          Is there possible to compare these two aliases?
          Thx

          Comment


          • #6
            The aliases are just something to refer to later on. The will replace the regular mySQL columnname or internal data-vector placeholder-name. Like if you use

            select count(*) from table, then mySQL needs to create a variable to store the count(*) in. By using an alias, you name that variable yourself. Like "select count(*) as reccount from table" which will then return you a recordset with one row, that has one variable (reccount) that holds the countvalue.

            So for your situation, you could do
            PHP Code:
            $sql='Select Date_Format(TS_Post_DT,"on %e/%c/%Y at %T") as date1, UI_Login FROM Topic_Start LEFT JOIN User_Info ON TS_UI_ID=UI_ID WHERE TS_D_ID='.$row['D_ID'] .' LIMIT 1';
            $result mysql_query($sql);
            $row=mysql_fetch_assoc($result);
            mysql_free_result($result);

            $sql='SELECT Date_Format(User_Option.UO_Last_Login,"on %e/%c/%Y at %T") as date2 FROM User_Option LEFT JOIN User_Info ON User_Option.UA_UI_ID=User_Info.UI_ID WHERE User_Option.UA_UI_ID='.$_SESSION['id'];
            $result2 mysql_query($sql);
            $row2=mysql_fetch_assoc($result2);
            mysql_free_result($result2);

            if (
            $row['date1'] == $row2['date2']){
                echo 
            'dates are the same.';
            } else {
                echo 
            'dates are different.';

            note : just quick code without errochecking etc.
            Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

            Comment

            Working...
            X