Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

determining number of hours between two times

Posted on 2004-03-26
5
Medium Priority
?
237 Views
Last Modified: 2013-12-24
i have the following start date and end date variables in a form:
 
startdatemonth - (values are 1-12)
startdateday - (values are 1-31..depeding upon the month)
startdateyear - (values are 2004 - 2010)
starttimehour - (values are 6, 6.5, 7, 7.5, 8, 8.5, etc.)
starttimeamorpm - (values are am/pm)

ex. 3/26/2004 8.5 am

enddatemonth - (values are 1-12)
enddateday - (values are 1-31..depeding upon the month)
enddateyear - (values are 2004 - 2010)
endtimehour - (values are 6, 6.5, 7, 7.5, 8, 8.5, etc.)
endtimeamorpm - (values are am/pm)

ex. 3/26/2004 5 pm

i basically want to determine the number of hours in between these two dates.

so for above example it should be 8.5 hours (where 8.5 above means 8:30)

how to do this?

0
Comment
Question by:Judy Deo
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:Tacobell777
ID: 10691659
You need to use dateDiff("h", yourdate1here, yourdate2here)
0
 

Author Comment

by:Judy Deo
ID: 10691868
but in what format should "yourdate1here" and  "yourdate2here" be? will it let me include the time part (i.e 7:30 am) ?
0
 
LVL 17

Assisted Solution

by:Tacobell777
Tacobell777 earned 600 total points
ID: 10692114
yes it will let you include the time, I should have said yourdatetimehere, it needs to be a valid date and time though.
If you look at the CF documentation and look up createdatetime(), it expects variables like so createDateTime(year, month, day, hour, minute, second)
Or string createDateTime("2004", "3", "26", "9", "20", "0")
0
 
LVL 10

Accepted Solution

by:
Mause earned 1400 total points
ID: 10698206
Hi

As Tacobell said you can use datediff to get the hours between the 2 dates.
But I gues yor problem is how to get the 8.5 to 8.30 or 20.30??
How do the users fill in the hours? width a textbox or a dropdown?
If its a dropdown its easy it will be:
<select name="starttimehour">
<option value="1,0">1</option>
<option value="'1','30'">1.5</option>
<option value="'2','0'">2</option>
<option value="'2','30'">2.5</option>
.
.
<option value="'13','0'">1</option>
<option value="'13','30'">1.5</option>
.
.
</select>

Then you can use createdatetime(startdateyear, startdatemonth, startdateday, starttimehour, "0")
AND
datediff("h",  createdatetime(startdateyear, startdatemonth, startdateday, starttimehour, "0"),  createdatetime(enddateyear, enddatemonth, enddateday, endtimehour, "0"))
to get the hours between the 2 dates

let us know
Mause
0
 

Author Comment

by:Judy Deo
ID: 10717749
thanks.
i forgot to ask one thing about the DateDiff function. i will ask it another question.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Integration Management Part 2
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question