Skip to main content
Inspiring
October 20, 2008
Question

please help dateformat issue

  • October 20, 2008
  • 5 replies
  • 955 views
Thanks for all the previous help but i have run into another problem and i think that i am just missing something with my eyes... I have come up with a login and i am making them change their password from the one i gave them initially. So my question lies in that i aslo have a time line for them to change their password within 90 days of the initial giving them their password but something is wrong with the date format... here is the code

<cfif (GetMember.DateCreated gt '#dateformat(10/07/2008()+90,"mm/dd/yyyy")#') and (GetMember.UpDated eq '#never#')>
<script>
self.location="PasswordUpdated.cfm";
</script>
<cfelse>





and here is the error i get



Invalid CFML construct found on line 134 at column 56.
ColdFusion was looking at the following text:
(

The CFML compiler was processing:

An expression beginning with dateformat, on line 134, column 35.This message is usually caused by a problem in the expressions structure.
An expression beginning with GetMember.DateCreated, on line 134, column 8.This message is usually caused by a problem in the expressions structure.
An expression beginning with (, on line 134, column 7.This message is usually caused by a problem in the expressions structure.

This topic has been closed for replies.

5 replies

Inspiring
October 21, 2008
Hi,

Saving a date into a text field creates a lot of problems. One of them is that it is almost impossible to compare dates like you want to.

Just change the format of the database field into a real date format and use one of the solutions provided above.

cheers,
fober
Participating Frequently
November 4, 2008
Try changing: <cfif Passwordexpire.DateCreated gt '#dateformat(10/07/2008 +90,"mm/dd/yyyy")#'and Passwordexpire.UpDated eq 'never'>

into: <cfif DateDiff('d',Passwordexpire.DateCreated,now()) gt 90 and Passwordexpire.UpDated eq 'never'>
LithcauseAuthor
Inspiring
October 21, 2008
I still am having problems with this... any other suggestions
Inspiring
October 20, 2008
Hi,

Are the following fields in your database real date fields or are they text fields: DateCreated, UpDated ?
(Dates should not be saved in text fields!)

I also have a question regarding the logic:
You want them to change their password in the first 90 days, but what happens if not?

A more common approach to password updates would be to require "customers must change their password at least every 90 days" (In this case only UpDated is relevant, and you can ignore when the account was created).

You can do that with the example below:
<cfif Passwordexpire.UpDated LT Dateadd( "d", -90, NOW() )>
<cflocation url="PasswordUpdated.cfm">
</cfif>

Since new customers have never updated their account, they would get immediately asked to update their password (from your initial password), as soon as they visit the site the first time.

cheers,
fober

LithcauseAuthor
Inspiring
October 20, 2008
this is not that type of app or site... the site is for old people and the owner does not want it to change every 90 days. the app will simply be for her (owner) to keep up with her own records of whos paid and who has not... if they have not, then they will not be able to get to the member area.. so i set it up the way she wanted it having set a temp password that she will e-mail to the affilliates to get into the member area.. once they login it promps to make them change the password... if they dont login to change it within 90days i have a page telling them to contact the owner so it can be changed...this is not for unlimited amount of users. it is only for aprox 100 users and very small amount of info in app such as news letters and a list of affiliates for them to print out... everything else works fine but this date thing... i have all varible passing as nvarchar ... i know not political corect but i have a deadline so just trying to get to run then i will normalize... changing date fields to date\time...datecreated is set already by me as '10/07/2008' and the Updated is set to 'never' once they change their password it populates the UpDated field with current date


<cfquery name="Passwordexpire" datasource="mytable">
Select UpDated, DateCreated
From Contacts
where (Email = '#session.Email#')
</cfquery>
<cfif Passwordexpire.DateCreated gt '#dateformat(10/07/2008 +90,"mm/dd/yyyy")#'and Passwordexpire.UpDated eq 'never'>
<script>
alert("you let you password expire !!!!!!.");
self.location="PasswordExpired.cfm";
</script>

<cfelse>
goes to the recordcount and checks to see if they are active member with the use of a bit field...
Participating Frequently
October 20, 2008
It's this bit that is throwing the error: dateformat(10/07/2008 ()+90
You can't have () there (I think you must have had a Now() before).

I'd suggest you have a look at the DateDiff function to make your code more readable. Something like this (not tested)

<cfset GetMember.DateCreated = CreateDate( 2007, 06, 10 ) />
<cfset GetMember.UpDated = CreateDate( 2008, 07, 10 ) />

<cfif IsDate( GetMember.UpDated ) AND ( DateDiff( 'd', GetMember.DateCreated, GetMember.UpDated ) gt 90 )>
FOO<hr />
<cfelse>
BAR<hr />
</cfif>
<!--- testing --->
<cfoutput>#DateDiff( 'd', GetMember.DateCreated, GetMember.UpDated )#</cfoutput>
LithcauseAuthor
Inspiring
October 20, 2008
thanks that helped.. yes you can only use () when using now... thanks
LithcauseAuthor
Inspiring
October 20, 2008
ok that solved that but still the issue of seing if it is over 90 days

<cfif Passwordexpire.DateCreated gt '#dateformat(10/07/2008 +90,"mm/dd/yyyy")#'and Passwordexpire.UpDated eq 'never'>
Inspiring
October 20, 2008
Your specific problem is probably due to the parentheses after your date string.

Your more general problem is the use of strings to reflect dates. Date format returns a string, not a date object. CreateDate is a better function in the context of your initial post.