473,378 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Calculating time difference

Hi,

I have a table called Bookings which has two important columns;
Booking_Start_Time and Booking_End_Time. These columns are both of type
DATETIME. Given any day how can I calculate how many hours are available
between the hours of 09.00 and 17.30 so a user can see at a glance how many
hours they have unbooked on a particular day (i.e. 8.5 hours less the time
of any bookings on that day), can this be done with a query
or do I have to work it out in my code?

Thanks for your help

Nov 12 '05 #1
1 8963
Shaun Thornburgh wrote:
Hi,

I have a table called Bookings which has two important columns;
Booking_Start_Time and Booking_End_Time. These columns are both of type
DATETIME. Given any day how can I calculate how many hours are available
between the hours of 09.00 and 17.30 so a user can see at a glance how many
hours they have unbooked on a particular day (i.e. 8.5 hours less the time
of any bookings on that day), can this be done with a query
or do I have to work it out in my code?

Thanks for your help


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It can be done in a query. I assume there are other columns in the
Bookings table that define what type of booking each record contains.
But, I'll go w/ the specs you gave. Hopefully the DateTime columns
have both the date and the time; otherwise, this could get ugly.

PARAMETERS [Date?] DateTime;
SELECT 8.5 - Sum(DateDiff("h", Booking_Start_Time, Booking_End_Time))
As Available
FROM Bookings
WHERE Booking_Start_Time Between [Date?] And DateAdd("n", -1,
[Date?]+1)

What it does:

8.5 - Sum(DateDiff("h", Booking_Start_Time, Booking_End_Time)) - since
there are 8.5 hours between 9:00 and 17:30, just subtract the total
booked hours from 8.5 to get the available hours.

If you have another column like Room_Number (something that identifies
what is stopping and starting on the DateTime values) you'd include it
in the SELECT clause and create a GROUP BY clause like this:

GROUP BY Room_Number

The WHERE clause uses the date entered by the user when the query
runs. It selects dates between the beginning of the Date (00:00:01)
and the end of the Date ((Date + 1 Day) - 1 minute , which equals
23:59 of the Date).

HTH,

MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP3nQboechKqOuFEgEQIHZwCgtDdrn3WH57Fpa6zx5Qkw12 mGz68An3SY
3mapIDQYaN7KJZ2UHKmzp8En
=bWlP
-----END PGP SIGNATURE-----

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the...
1
by: Tony Williams | last post by:
I have a table with two fields, txtvalue (a number field) and txtmonth ( a date/time field). I want to create a report that shows the difference in value between the value in txtvalue in one value...
6
by: Tony Williams | last post by:
SORRY I know we shouldn't do this but I'm desperate for an answer to this and the previous post didn't seem to get a response. I have a table with two fields, txtvalue (a number field) and...
3
by: Ron Vecchi | last post by:
I need to calculate the age of a person based on a DateTime BirthDate I was thinking TimeSpan ts = DateTime.Now - BirthDate; //I can get the days but not years. // I could check each...
4
by: iamonthisboat | last post by:
I have a data set like so: UTC_TIME Timestamp NodeID Message Flag Line Station 11/19/2005 10:45:07 1132397107.91 1 3 5 1028 1034...
2
by: slinky | last post by:
Anyone know how to calculate the difference between two times displayed in two textboxes? I'm starting out with two textboxes: "txtCallTimeBegins" & "txtCallTimeEnds" this yielded: 6/7/2007...
5
by: Julius | last post by:
Hej dudes, I need to calc the difference between two timestamps / dates ... For example what i need to calculate: Date 1: 2007.11.06 - 20:13:04 Date 2: 2007.11.07 - 21:13:04 Difference:...
6
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
6
by: veer | last post by:
Hi i use Datediff() and it return only hours but i want total time with minutes and seconds at the same time i use following code for all this and it works fine but when the the time came which i...
3
by: mfaisalwarraich | last post by:
Hi everybody. I have some problem while calculating time. i have employees who are working on hourly basis. i want to calculate the time. for example if an employee start working at 11:00pm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.