Solved

determining number of hours between two times

Posted on 2004-03-26
5
218 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
json_decode return null? 8 89
Finding an Azure real-time monitoring dashboard 2 68
Web server settings related to keepalive 1 122
Systems talking to each other 5 131
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…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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