ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

edit_date comparison question

April 29, 2009 7:47pm

Subscribe [2]
  • #1 / Apr 29, 2009 7:47pm

    dwex

    94 posts

    I recently implemented the Edit Comments plugin on our site. One of my co-authors has asked me to implement a “Last edited at: XXXX” flag into edited comments. To do this, I need to be able to compare the ‘gmt_comment_date’ and ‘edit_date’ variables, and only display the flag line if they differ.

    I was looking through this thread and find myself more confused that when I started, so I’m going to ask a new question rather than just appending to that thread, if that’s OK.

    I was thinking I needed to write a bit of PHP for this, since one is a time_t and the other is a timestamp, but then I saw that other thread. I don’t understand how this is working. It looks to me that the example “solution” is doing a string comparison of the timestamps, but it’s doing it with textual month names. A string comparison would only work if it’s formatted as YYYYMMDDHHMMSS, wouldn’t it? Or is there something happening behind the scenes that’s converting these into time_t’s and comparing them arithmetically?

    Also, since the gmt_comment_date is generated by the EE engine while edit_date is generated by the database at update time, there’s no guarantee that they are identical when a new comment is created, right? I’m thinking I need to do an integer comparison with a delta of 1 second to make sure that I only display my flag line if the comment is edited after its initial creation.

    Looking forward to your thoughts on this.

  • #2 / Apr 30, 2009 7:09am

    Ingmar

    29245 posts

    It looks to me that the example “solution” is doing a string comparison of the timestamps, but it’s doing it with textual month names. A string comparison would only work if it’s formatted as YYYYMMDDHHMMSS, wouldn’t it?

    Only if you wanted to do smaller than / bigger than comparisons. A simple “not equal” would work with names as well. That said, I personally prefer UNIX timestamps, much easier and cleaner to work with.

    I suggest we discuss this in more detail in Howto, if you want to. Moving thread there.

  • #3 / Apr 30, 2009 10:35am

    dwex

    94 posts

    What is the correct way for me to get the timestamps into PHP in my template? In the thread I referenced, you said that you shouldn’t use the {*date*} variables without the format= parameter. Do I need to do a DB query against the comment ID to extract the comment time and edit time? I’d really prefer to not add an extra DB query for every comment.

    Thanks.

  • #4 / Apr 30, 2009 10:57am

    Ingmar

    29245 posts

    In the thread I referenced, you said that you shouldn’t use the {*date*} variables without the format= parameter.

    That’s right; because that way, regardless of how the date is stored in the database, the output can be formatted in accordance with your needs.

    Do I need to do a DB query against the comment ID to extract the comment time and edit time?

    No, you simply use, say

    {comment_date format="%U"}
    {edit_date format="%U"}

    You can also use any other format, of course. Really quite straight forward, actually.

  • #5 / Apr 30, 2009 10:58am

    dwex

    94 posts

    doh! my bad 😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases