Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare dates.....

Status
Not open for further replies.

gadjodilo77

Programmer
Sep 23, 2005
79
NL
Hi,

I have a question. I have to get information out of a Novell database using LDAP. One thing is the "LastRegisteredTime" all that is possibble and it give the dat like this:

20060507072033Z To us e this date I had to rearrange it a little bit...

So it ends up like this:

2006-05-07.

What I really want to do is to compare this date with the current date... And if the date has another (earlyer) year or a month value of two months earlier then the current month (in the same year)... Then I would like to show the data for these records...

Currently I made something like this:

However it still doesn't do what I want:

<cfset jaar1 = DateFormat(Now(), "YYYY-MM-DD")>

<cfldap action="QUERY"
name="qtest"
attributes="cn, wMNAMEUser, zENINVSerialNumber, ZENINVlastscandate, wMLastRegisteredTime, lastLoginTime"
start=""
scope="SUBTREE"
filter="objectClass=Workstation"
server=""
>

<!--- last registered date bewerken--->
<cfset jaar= left(qtest.wMLastRegisteredTime, 4)>
<cfset maand= Mid(qtest.wMLastRegisteredTime,5,2)>
<cfset dag= Mid(qtest.wMLastRegisteredTime,7,2)>
<cfset datum = #DateFormat(CreateDate(jaar, maand, dag), "yyyy-mm-dd")#>


<cfloop query="qtest">
<cfset jaar= left(qtest.wMLastRegisteredTime, 4)>
<cfset maand= Mid(qtest.wMLastRegisteredTime,5,2)>
<cfset dag= Mid(qtest.wMLastRegisteredTime,7,2)>
<cfset datum = #DateFormat(CreateDate(jaar, maand, dag), "yyyy-mm-dd")#>



<cfset comparison = DateCompare(datum, jaar1)>
<cfswitch expression = #comparison#>
<cfcase value = "-1">
<h3><cfoutput>#DateFormat(datum)#
</cfoutput> (Date 1) is
earlier than <cfoutput>#DateFormat(jaar1)#
</cfoutput> (Date 2)</h3>
<I>The dates are not equal</I>
</cfcase>
<cfcase value = "0">
<h3><cfoutput>#DateFormat(datum)#
</cfoutput> (Date 1) is equal
to <cfoutput>#DateFormat(jaar1)#
</cfoutput> (Date 2)</h3>
<I>The dates are equal!</I>
</cfcase>
<cfcase value = "1">
<h3><cfoutput>#DateFormat(datum)#
</cfoutput> (Date 1) is later
than <cfoutput>#DateFormat(jaar1)#
</cfoutput> (Date 2)</h3>
<I>The dates are not equal</I>
</cfcase>
<CFDEFAULTCASE>
<h3>This is the default case</h3>
</CFDEFAULTCASE>
</cfswitch>
</loop>


Is there somebody who could help me? The yyy-mm-dd notation is usable in MySQL, but it is not a Coldfusion date I believe?? (maybe?). Could that also be a problem?

Hopefully somebody understands what I mean.

Thank you in advance.

Regards,

Kabbi

 

I also keep getting this error if I try to compare it and show the differences per month.

"06" is not a valid date/time format.
The following list contains all valid datepart masks:
yyyy - Year
q - Quarter
m - Month
d - Day
w - Weekday
ww - Week
h - Hour
n - Minute
s - Second


The error occurred in C:\xampp\htdocs\bar\ONZIN\LastRtime.cfm: line 91

89 :
90 :
91 : <cfset comparison = DateCompare(datum, jaar1, maand1)>
92 : <cfswitch expression = #comparison#>
93 : <cfcase value = "-1">



code:

<cfset jaar1 = DateFormat(Now(), "YYYY-MM-DD")>
<cfset maand1 = DateFormat(Now(), "mm")>

<cfldap action="QUERY"
name="qtest"
attributes="cn, wMNAMEUser, zENINVSerialNumber, ZENINVlastscandate, wMLastRegisteredTime, lastLoginTime"
start=""
scope="SUBTREE"
filter="objectClass=Workstation"
server=""
>

<!--- last registered date bewerken--->
<cfset jaar= left(qtest.wMLastRegisteredTime, 4)>
<cfset maand= Mid(qtest.wMLastRegisteredTime,5,2)>
<cfset dag= Mid(qtest.wMLastRegisteredTime,7,2)>
<cfset datum = #DateFormat(CreateDate(jaar, maand, dag), "yyyy-mm-dd")#>


<cfloop query="qtest">
<cfset jaar= left(qtest.wMLastRegisteredTime, 4)>
<cfset maand= Mid(qtest.wMLastRegisteredTime,5,2)>
<cfset dag= Mid(qtest.wMLastRegisteredTime,7,2)>
<cfset datum = #DateFormat(CreateDate(jaar, maand, dag), "yyyy-mm-dd")#>



<cfset comparison = DateCompare(datum, jaar1, maand1)>
<cfswitch expression = #comparison#>
<cfcase value = "-1">
<h5><cfoutput>#DateFormat(datum, "yyyy-mm-dd")#
</cfoutput> (Datum nds) is
jonger dan <cfoutput>#DateFormat(jaar1, "yyyy-mm-dd")#
</cfoutput> (Datum)</h5>
<I>niet gelijk!</I>
</cfcase>
<cfcase value = "0">
<h5><cfoutput>#DateFormat(datum, "yyyy-mm-dd")#
</cfoutput> (Datum nds) is gelijk
aan <cfoutput>#DateFormat(jaar1, "yyyy-mm-dd")#
</cfoutput> (Datum)</h5>
<I>De datum is gelijk!</I>
</cfcase>
<cfcase value = "1">
<h5><cfoutput>#DateFormat(datum, "yyyy-mm-dd")#
</cfoutput> (Datum nds) is later
dan <cfoutput>#DateFormat(jaar1, "yyyy-mm-dd")#
</cfoutput> (Datum)</h5>
<I>De data is ongelijk</I>
</cfcase>
<CFDEFAULTCASE>
<h5>default!</h5>
</CFDEFAULTCASE>
</cfswitch>
</cfloop>


 
Hi,

Thank you very much for your answer. It works!

Regards,

Kabbi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top