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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Times

Status
Not open for further replies.

anastasia

Programmer
Dec 13, 2000
111
GB
Hi, I am using Cold Fusion code in a WAP page. I have the following code:

<CFSET bookdate = DateFormat(#url.bookdate#, &quot;dd, mm, yy&quot;)>
<CFSET booktime = TimeFormat(#url.booktime#, &quot;hh, mm,&quot;)>

<cfif #bookdate# GT #EndDate#>
<b>Error!</b><br/>
Booking Date: Season ends 30/09/01
</cfif>

<cfif #bookdate# LT #StartDate#>
<b>Error!</b><br/>
Booking Date: Season Starts 01/03/01
</cfif>

<cfif #booktime# GT #EndTime#>
<b>Error!</b><br/>
Booking Time: End Time 20.00
</cfif>

<cfif #booktime# LT #StartTime#>
<b>Error!</b><br/>
Booking Time: Start Time 08.00
</cfif>

</CFOUTPUT>

The dates and times being tested test what the user has entered in a previous form to what is held within a database. The dates work fine however the times do not. Whatever time I enter I get the error Booking Time: Start Time 08.00. If I enter times greater than 08.00 say 09.00 I get the same error but shouldn't.

Any ideas appreciated.

Thanks.

 
hi Anastasia - You are passing these variables, date and time, through your URL, right? I would recommend against this, maybe use a form submit instead; but if you are passing them, why not format them on the first page instead of right here?

Your use of the timeFormat() function is the problem. As long as the dates/ times you're comparing are in the same format as what you see below everything should work fine.

Try this:

<CFSET bookdate = DateFormat(url.bookdate, &quot;mm-dd-yyyy&quot;)>
<CFSET booktime = TimeFormat(url.booktime, &quot;hh:mm&quot;)>

The dateFormat() and timeFormat() functions aren't like the createDate(), createTime() functions. These allow you to create dates of type ODBC only, while you're really looking to create your own combination using predefined symbols. (d for day, m for month).

Let me know if I helped.
 
Thanks strantheman for your reply but unfortunately still no luck. I get the error message displaying for the date when it should not.

Thanks anyway.
 
Hi Anastasia.

You never tell us how you have set your variable, StartTime.
I suspect you have set it as:
<CFSET StartTime = &quot;08.00&quot;>

You also never tell us / display exactly what comes through in URL.booktime.

I would suggest that you output to your screen
#url.booktime#
and
#TimeFormat(url.booktime, &quot;hh, mm,&quot;)#

This will enable you to see exactly what is being compared.

Hope this helps. If not, give us those details and maybe we can work it out!

 
Hi jackied

I am passing through the time and date with the post method instead of in the url. Here is the code:

<do type=&quot;accept&quot; label=&quot;Add&quot;>
<go href=&quot;add.cfm&quot; method=&quot;post&quot;>
<postfield name=&quot;bookdate&quot; value=&quot;$bookdate&quot;/>
<postfield name=&quot;booktime&quot; value=&quot;$booktime&quot;/>

</go>
</do>

<p>

Date:<input type=&quot;text&quot; name=&quot;bookdate&quot; size=&quot;8&quot; maxlength=&quot;8&quot; format=&quot;NNANNANN&quot;/>
Time:<input type=&quot;text&quot; name=&quot;booktime&quot; size=&quot;5&quot; maxlength=&quot;5&quot; format=&quot;NNANN&quot;/>

</p>

When the variables are passed to the next form I do my error checking as above.

The variables that are being tested against what the user enters are held within a database. The StartTime/EndTime is set to the Data Type Date/Time and is formatted as Short Time and has an input mask as 00:00;0;_ The time is displayed as 08:00 and 20:00. The same applies to the StartDate/EndDate again Data Type of Date/Time and has an input mask of 99/99/00;00;_ the output to this is 01/03/01.

The output I get within the WML page is the date now formatted as 01/03/01 and the time as 12:30. I have changed the DateFormat and used / instead of , if that helps, and used the TimeFormat as specified above.

Thanks for your help.
 
hi anastasia,

Sorry we weren't able to resolve this earlier, but as long as you're collecting proper book dates from the user, and the database is recording them properly.. and you can output the screen those dates in whatever format you want using the dateformat() function, your problem must lie in the CFIFs.

Try this:

<cfif dateCompare(startTime, bookTime) LTE -1>
<b>Error!</b><br/>
Booking Time: Start Time 08.00
</cfif>

Example:
dateShipped = monday
dateToday = wednessday

<CFIF datecompare(dateShipped, dateToday) LTE -1>
Item shipped before today.
</CFIF>

Hope this helps. Let me know what you've tried so far.
 
Sorry strantheman still no joy, with the code above whaever time I enter the error is displayed. Someone mentioned using the ODBC format which I have tried as below but still not working. I have tried your code without the ODBC format and with the TimeFormat etc but to no success?

<CFOUTPUT QUERY=&quot;season&quot;>

<CFSET time = #CreateODBCTime(booktime)#>

<cfif dateCompare(time, bookTime) LTE -1>
<b>Error!</b><br/>
Booking Time: Start Time 08.00
</cfif>

</CFOUTPUT>


 
Here, anastasia, see what you can do with this. It seems to work the way you want it to. I tried entering a variety of times, and I seemed to get the appropriate responses. Also, just in case you weren't aware of it, the TimeFormat function is case sensitive for the hour. &quot;HH&quot; uses a 24 hour clock, &quot;hh&quot;, uses a 12 hour clock. Hope you can make something of this.
Code:
<CFSET StartTime=#CreateTime(08,00,00)#>
<CFOUTPUT>StartTime = #StartTime#</CFOUTPUT><BR><BR>
<CFSET EndTime=#CreateTime(20,00,00)#>
<CFOUTPUT>EndTime = #EndTime#</CFOUTPUT><BR><BR>
<CFSET Booktime=#CreateTime(23,00,00)#>
<CFOUTPUT>Booktime = #BookTime#</CFOUTPUT><BR><BR>

<CFOUTPUT>

<cfif #booktime# GT #EndTime#>
<b>Error!</b><br/>
Booking Time: End Time 20.00
</cfif>

<cfif #booktime# LT #StartTime#>
<b>Error!</b><br/>
Booking Time: Start Time 08.00
</cfif>

</CFOUTPUT>
Good luck! :)

Calista
 
calista your code works fine as is. I have since tried the code without putting any date format on it or ODBC format on it as with these it was outputing the dates and times entered by the user incorrect.

If I test just the times as mentioned at the beginning this works fine using two IF statements. the problem seems to occur when I introduce more IF statement as above. 2 for testing the time then followed by another 2 IF statements testing the date this is when problems tend to occur. I was having the same kind of problem in ASP but not so problematic.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top