Solved

datediff in cfml

Posted on 2010-09-22
8
428 Views
Last Modified: 2012-06-27
Hello experts.
I want to use the datediff function i had using mssql now with mysql but i can't get it work.
Any help?
<cfquery name="gettime" datasource="#request.dsn#">
       SELECT requestpw,user_ID
       From users
       Where uuidpw = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.resetpw#">
     </cfquery>
     <cfif gettime.recordcount NEQ 0>
         <cfscript>
             date1 = #LSParseDateTime(gettime.requestpw)#;
         date2 = now();
             REQUESTEXITS = 1;
             </cfscript>
          <cfif dateDiff("h",date1, Date2) lt 24 >
            <cfset oldrequest = 1 />
           <cfelse>
         <cfset oldrequest = 0 />
        </cfif>
0
Comment
Question by:Panos
  • 4
  • 2
8 Comments
 
LVL 1

Assisted Solution

by:gigipaul
gigipaul earned 150 total points
Comment Utility
DateDiff in Mysql will give only Days.
You need to use SEC_TO_TIME(dt1-dt2) will give the difference in seconds and see if its more than 24 hours.
Hope this helps
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
>> i can't get it work.

The code posted isn't using database functions, it's using CF's DateDiff() function.  Can you explain what's not working... rre you getting an error message?
0
 
LVL 2

Author Comment

by:Panos
Comment Utility
Hi.
agx. You are right.It is cf code but for the following test code i get output 0.
<cfset set = '0879E1C5-DF40-8B46-5E7036434BBF14C2'>
<cfquery name="gettime" datasource="#request.dsn#">
       SELECT requestpw,user_ID
       From users
       Where uuidpw = <cfqueryparam cfsqltype="cf_sql_varchar" value="#set#">
     </cfquery>
 <cfif gettime.recordcount NEQ 0>
         <cfscript>
             date1 = #LSParseDateTime(gettime.requestpw)#;
         date2 = now();
             REQUESTEXITS = 1;
             </cfscript>
          <cfif dateDiff("h",date1, Date2) lt 24 >
            <cfset oldrequest = 1 />
           <cfelse>
         <cfset oldrequest = 0 />
        </cfif>
      </cfif>
     
      <cfset dif = dateDiff("h",Date2, date1)>
        <cfoutput>#dif#</cfoutput>

( requestpw value in db = 2010-09-22 16:59:23)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 2

Author Comment

by:Panos
Comment Utility
Hi gigipaul
24 hours are 1 day.That's it what i need.The problem is somewhere else.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 350 total points
Comment Utility
>> date1 = #LSParseDateTime(gettime.requestpw)#;
>> date2 = now();
<cfif dateDiff("h",date1, Date2) lt 24 >

Why use LSParseDateTime() there? The value from the db should already be a date object.  I'm wondering if that's doing something unexpected to the value.  

Display both dates, and the dateDiff what are the results?
<cfoutput>
#date1#  #date2#   #dateDiff("h",date1, Date2)#
</cfoutput>
0
 
LVL 2

Author Comment

by:Panos
Comment Utility
Hi.
I don't know what the problem wasbut it is working now with and without LSParseDateTime().
Thank you both.
0
 
LVL 2

Author Closing Comment

by:Panos
Comment Utility
Thank you both for your help.I gave some points to expert  gigipaul for his interest in my question.It was my mistace to include the mysql zone.
regards
panos
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now