Skip to main content
July 25, 2007
Answered

Is there a way to update this field?

  • July 25, 2007
  • 5 replies
  • 453 views
Hi Everyone,

I have attached my code. Basically I am trying to capture a total labor hours and a total travel hours based on task. I am also calculating a total cost and a total price. The labor hours and travel hours are based on times (miliary) that are entered into the depart, sa1, sdepart and sa2 form fields.

Now the code performs how I want it to, but I would like to try and add a piece that would modify the number that it placed into the labor and travel fields to reflect a regular sum not a sum based on miliary. I hope that I worded that correctly.

For example: Depart 0600 SA1 0800 SDEPART 1500 SA2 1530 give me a total for travel of 230 and I want it to be 2.5 or 3

Thanks
Sue
    This topic has been closed for replies.
    Correct answer cf_dev2
    > Could I do something like this?

    Hard to say since I can't see your form. Why do you need a cfif? Is it a self-posting form?

    > <CFIF IsDefined(Form.depart)>

    That's the wrong syntax for IsDefined(). You need quotes around the variable name: IsDefined("Form.depart")

    5 replies

    July 26, 2007
    Thank you. I typed it wrong in my code on the page also :)

    I tested it several times and with several scenarios, it seems to be working just fine.

    Thanks for your help.

    Sue
    cf_dev2Correct answer
    Inspiring
    July 26, 2007
    > Could I do something like this?

    Hard to say since I can't see your form. Why do you need a cfif? Is it a self-posting form?

    > <CFIF IsDefined(Form.depart)>

    That's the wrong syntax for IsDefined(). You need quotes around the variable name: IsDefined("Form.depart")
    July 26, 2007
    Could I do something like this?

    <CFIF IsDefined(Form.depart)>
    <CFSET depart="#Form.depart#">
    <CFELSE>
    <CFSET depart="#Right("0000"&GetTask.depart, 4)#">
    </CFIF>
    Inspiring
    July 25, 2007
    What is the data type of the time field? Assuming its "time" or "datetime" you could use timeformat
    <cfoutput>#TimeFormat(theTimeColumn, "hhmm")#</cfoutput>

    If not I suppose you could always pad the value with leading zeroes.
    <!--- sample value without the leading zero --->
    <cfset theTimeValue = "600">
    <cfoutput>#Right("0000"& theTimeValue, 4)#</cfoutput>
    Inspiring
    July 25, 2007
    One option is convert the form values to a time or datetime. Then use dateDiff() to get the travel time in minutes and divide by 60.

    <!--- your form fields --->
    <cfset form.Depart = "0600">
    <cfset form.SA1 = "0800">
    <cfset form.SDepart = "1500">
    <cfset form.SA2 = "1530">

    <cfset DepartTime = createTime(left(form.Depart, 2), right(form.Depart, 2), 0)>
    <cfset SA1Time = createTime(left(form.SA1, 2), right(form.SA1, 2), 0)>
    <cfset Travel1 = dateDiff("n", DepartTime, SA1Time)/ 60>
    <cfset SDepartTime = createTime(left(form.SDepart, 2), right(form.SDepart, 2), 0)>
    <cfset SA2Time = createTime(left(form.SA2, 2), right(form.SA2, 2), 0)>
    <cfset Travel2 = dateDiff("n", SDepartTime, SA2Time)/ 60>

    <hr>
    <cfoutput>
    Travel1 = #Travel1#<br>
    Trave2 = #Travel2#<br>
    Total = #(Travel1 + Travel2)#
    </cfoutput>

    July 25, 2007
    Thank You! That is exactly what I wanted it to do. I have never tried to convert to a datetime. Now I know how!

    The only thing that I am working out is when I modified the task and I have time with a "0600" the database of course drops the 0 so when I modified I get an error and have to reenter the form field with a zero to get it to complete.

    Not sure how to get around that, or if I can.