Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

determining number of hours between two times

Posted on 2004-03-26
5
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

705 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