Solved

Time compare

Posted on 2009-05-19
7
303 Views
Last Modified: 2012-05-07
I am trying to create a code set that will tell me how old reports are. For example. I have a field in the ACCESS db that is "report_date" and is a date/time. I want to break the reports down by
1. Less than 24 hours
2. 24-48 hours
3. 3-7 days
4. 7+ days

I know I can use datecompare, but I am having trouble with the less than 24 hours and the 24-48 hours part.

How can I take report_date < 24 hours and cull those records from the query and report_date between 24-48 hours with a date.
0
Comment
Question by:dudeatwork
7 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24425221
try this code it works just fine
<cfset lTime1="2/18/2008 11:31:15 AM">
<cfset lTime2 = "2/15/2008 15:31:15 PM">
<cfif DateDiff("h",lTime1,lTime2) gt 24 and DateDiff("h",lTime1,lTime2) lt 48>
Hello
<cfelse>
Not Hello
</cfif>
0
 

Author Comment

by:dudeatwork
ID: 24425347
What if the table is broken to two columns report_date and report_time. Can I concatenate in the query report_date & report_time as mydate?
I am trying to get the condition in the cfquery for the record sets.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 24425967
> Can I concatenate in the query report_date & report_time as mydate?

I believe Access stores date/time values as numbers internally. So just add them together. Then compare that value to whatever date and time value you need (24 hours ago, 24-28 hours, etc).  It should work fine, though it is probably the ideal method.  (I prefer to store date and time values in one field, because of exactly this type of scenario.)
<!--- create the time ranges you need --->

<cfset dateTimeNow = now()>

<cfset twentyFourHoursAgo = dateAdd("d", -24, dateTimeNow)>

<cfset twentyEightHoursAgo = dateAdd("d", -28, dateTimeNow)>

....
 

<cfquery name="lessThan24Hrs" datasource="YourDatasource">

	SELECT 	report_date, report_time, OtherColumns ...

	FROM 	yourTable

	WHERE	(report_date+ report_time) > <cfqueryparam value="#twentyFourHoursAgo#" cfsqltype="cf_sql_timestamp">

</cfquery>
 

<cfquery name="from24To28Hours" datasource="YourDatasource">

	SELECT 	report_date, report_time, OtherColumns ...

	FROM 	yourTable

	WHERE	(report_date+ report_time)	BETWEEN 

			<cfqueryparam value="#twentyFourHoursAgo#" cfsqltype="cf_sql_timestamp"> AND

			<cfqueryparam value="#twentyEightHoursAgo#" cfsqltype="cf_sql_timestamp">

</cfquery>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 52

Expert Comment

by:_agx_
ID: 24425974
> though it is probably the ideal method.

... though it is probably NOT the ideal method.
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24428353
@_agx_:  :) typos again! your code is getting records from 24 and 28 DAYS ago... and 28 should be 48 according to the question...

Azadi
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24430175
Ack!   Thank you :)   I was focusing on the Access db differences.  Just a _slight_ difference ;-)

Thanks to azadi, the corrected date logic is:

<cfset twentyFourHoursAgo = dateAdd("h", -24, dateTimeNow)>
<cfset twentyEightHoursAgo = dateAdd("h", -28, dateTimeNow)>
0
 

Author Closing Comment

by:dudeatwork
ID: 31583154
Nice try though, thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Having an issue with NumberFormat 7 58
Weird Behavior in ColdFusion 8 70
Coldfusion remove square brackets from string 4 86
Coldfusion Mysql get data from two tables 3 78
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

947 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

20 Experts available now in Live!

Get 1:1 Help Now