Solved

determining number of hours between two times

Posted on 2004-03-26
5
216 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:sagardeo
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

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

Author Comment

by:sagardeo
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 150 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 350 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:sagardeo
ID: 10717749
thanks.
i forgot to ask one thing about the DateDiff function. i will ask it another question.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now