Set the remaining time in -datediff in coldfusion

Hello experts
I have a users table with dateregister column (in datetime format).
A registered user has 24 hours to activate his account.
When he is trying to login without having activated his account i want to show him what time he has left to activate it or else his account will be deleted.
I have the query:
<cfquery name="CheckPersonAct" datasource="#request.dsn#">
        SELECT Password, email, user_ID ,Activation, user_uuid,dateregister
        FROM users
        WHERE email = <cfqueryparam value="#Form.lemail#" cfsqltype="CF_SQL_VARCHAR">
        AND Password = <cfqueryparam value="#VARIABLES.hashedPass#" cfsqltype="cf_sql_varchar">
        AND Activation = <cfqueryparam value="0" cfsqltype="cf_sql_numeric">
      </cfquery>
 
LVL 2
PanosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

azadisaryevCommented:
again, you could get the remaining time either in your query, or using cf at output.

in your query you can do something like this:
[this is MySQL-specific syntax; check your db for correct syntax/functions to use]

<cfquery name="CheckPersonAct" datasource="#request.dsn#">
SELECT Password, email, user_ID ,Activation, user_uuid, HOUR(TIMEDIFF(DATE_ADD(dateregister, INTERVAL 24 HOUR), NOW())) AS h, MINUTE(TIMEDIFF(DATE_ADD(dateregister, INTERVAL 24 HOUR), NOW())) AS m
FROM users
WHERE email = <cfqueryparam value="#Form.lemail#" cfsqltype="CF_SQL_VARCHAR">
AND Password = <cfqueryparam value="#VARIABLES.hashedPass#" cfsqltype="cf_sql_varchar">
AND Activation = <cfqueryparam value="0" cfsqltype="cf_sql_numeric">
</cfquery>
<cfoutput>
you have #CheckPersonAct.h# hour<cfif CheckPersonAct.h gt 1>s</cfif> and #CheckPersonAct.m# minute<cfif CheckPersonAct.m gt 1>s</cfif> remaining to activate your account
</cfoutput>


using just cf, you can do it this way:

<cfquery name="CheckPersonAct" datasource="#request.dsn#">
SELECT Password, email, user_ID ,Activation, user_uuid, dateregister
FROM users
WHERE email = <cfqueryparam value="#Form.lemail#" cfsqltype="CF_SQL_VARCHAR">
AND Password = <cfqueryparam value="#VARIABLES.hashedPass#" cfsqltype="cf_sql_varchar">
AND Activation = <cfqueryparam value="0" cfsqltype="cf_sql_numeric">
</cfquery>
<cfset mdiff = datediff('n', now(), dateadd('h', 24, CheckPersonAct.dateregister))>
<cfset m = mdiff mod 60>
<cfset h = (mdiff-m)/60>
<cfoutput>
you have #h# hour<cfif h gt 1>s</cfif> and #m# minute<cfif m gt 1>s</cfif> remaining to activate your account
</cfoutput>

of course, both examples assume your dateregister column is datetime/timestamp data type.

Azadi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PanosAuthor Commented:
Thank you again azadi for your help
regards
panos
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.