9 Replies Latest reply: Mar 12, 2012 11:37 PM by -==cfSearching==- RSS

    Difference between 2 timestamps

    lovewebdev Community Member

      I'm not sure why my results are giving me 0. I'm trying to do a simple date difference. Here's my code:

       

      <cfset nowtime = now()>

       

      <cfif DateDiff("s", getpost.dtstamp, nowtime) lt 60>

        <cfset thedate = DateDiff("s", getpost.dtstamp, nowtime)  & " seconds ago">

       

        <cfelseif DateDiff("m", getpost.dtstamp, nowtime) lt 60>

        <cfset thedate = DateDiff("m", getpost.dtstamp, nowtime)  & " minutes ago">

       

         <cfelseif DateDiff("h", getpost.dtstamp, nowtime) lte 23>

        <cfset thedate = DateDiff("h", getpost.dtstamp, nowtime)  & " hours ago">

       

       

        <cfelseif DateDiff("d", v.dtstamp, nowtime) lte 7>

        <cfset thedate = DateDiff("d", getpost.dtstamp, nowtime) & " days ago">

       

          <cfelse>

        <cfset thedate = dateformat(getpost.dtstamp, "mmmm dd")>

      </cfif>

       

       

      When I displayed the original variables it shows:

       

      getpost.dtstamp = 2012-03-10 17:33:25.0 I don't know where this .0 is coming from because the database doesn't show that.

      now = {ts '2012-03-12 16:16:02'}

       

      I'm getting 0.