• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Difference between 2 timestamps

Participant ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

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.

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Mar 12, 2012 Mar 12, 2012

Okay, that explains it. You have got the wrong DateDiff unit.  "m" stands for months, not minutes.

Votes

Translate

Translate
Valorous Hero ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

Zero what: seconds ago, minutes ago, ....?  What is the data type of the dtstamp column?

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

Btw, are you intentionally using a different variable there?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

Just a mistake as I pasted my code on the forum it should be the same as the variables above it. That's not the cause of the error

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

That was just an fyi in case it was not a copy/paste error 😉

What about the first two questions?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

@-==cfSearching==- oh sorry. I missed that. So all results are stuck at saying "0 minutes ago"

and the column is a timestamp mysql

@dan same thing. it dumps the seconds correctly but just stops at the minutes and says 0 minutes. it goes no further, even though all differences between posts are way past 60 minutes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

I don't know if the error is being caused by that random .0. I don't even know where it's coming from. I checked the value of the timestamp column and there is no .0 in there but this is what's dumping out.

getpost.dtstamp = 2012-03-10 17:33:25.0

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

LATEST

I don't if the error is being caused by that random .0. I don't even know where it's coming from.

I checked the value of the timestamp column and there is no .0 in there but this is what's dumping out.

getpost.dtstamp = 2012-03-10 17:33:25.0

That is just a user friendly representation of the timestamp value as a string. Internally, it is a big unreadable number xxxxxxxxx. But since you are not performing a string comparison, its not relevant.

Message was edited by: -==cfSearching==-

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

Okay, that explains it. You have got the wrong DateDiff unit.  "m" stands for months, not minutes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

OMG! thanks. I always forget n for minutes lol

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

When in doubt, look at your data.  What does this give you?

<cfdump var = "nowtime is #nowtime# dtstamp is #getpost.dtstamp# datediff seconds is  #DateDiff("s", getpost.dtstamp, nowtime)#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation