LeanDev
LeanDev

Reputation: 251

The value {t cannot be converted to a number coldfusion

i just learning something about coldfusion. and trying datetime with createdatetime. but there show error "The value {t cannot be converted to a number" in the line of cfset txtStartTime and cfset txtEndTime.

<cfset txtStartTime = createdatetime(year(txtStartDate),month(txtStartDate),day(txtStartDate),left(txtStartTime,2),right(txtStartTime,2),00)>
<cfset txtEndTime = createdatetime(year(txtEndDate),month(txtEndDate),day(txtEndDate),left(txtEndTime,2),right(txtEndTime,2),00)>

Am I doing something wrong? For your reference, my createdatetime value looks like this: txtStartTime = {ts '2014-07-22 08:00:00'} and txtEndTime{ts '2014-07-22 17:00:00'}

Thank you so much guys.

Upvotes: 1

Views: 563

Answers (3)

Scott Stroz
Scott Stroz

Reputation: 7519

It seems as if you are actually starting with something ColdFusion recognizes as a date/time, hence the {t issue. It also seems you want to use the hours and minutes from those initial dates/times and use 00 for the seconds. If this is the case you can simply do this:

<cfset txtStartTime = createdatetime(year(txtStartDate),month(txtStartDate),day(txtStartDate),hour(txtStartTime),minute(txtStartTime),00)>
<cfset txtEndTime = createdatetime(year(txtEndDate),month(txtEndDate),day(txtEndDate),hour(txtEndTime),minute(txtEndTime))>

Upvotes: 4

Adam Cameron
Adam Cameron

Reputation: 29870

Right, so you have this:

left(txtStartTime,2)
right(txtStartTime,2)

And as you point out, the string-value of txtStartTime is:

{ts '2014-07-22 08:00:00'}

So what's the value of left("{ts '2014-07-22 08:00:00'}", 2) ? it's {t

What's the value of right("{ts '2014-07-22 08:00:00'}",2)? it's '}

That's now what you want, is it?

What are you actually trying to do? Not "how are you trying to solve it", but what are you trying to do?

Upvotes: 2

duncan
duncan

Reputation: 31920

Your problem is your time looks like {ts '2014-07-22 08:00:00'}. When you use left() or right() on that, you're treating it as a string rather than a date object.

So the 2 left-most characters would be {t, which isn't valid for the hours value of createDateTime, hence the error message.

Upvotes: 4

Related Questions