473,624 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help With a DATETIME Query

Hi,

I have a table called Bookings which has two important columns;
Booking_Start_D ate and Booking_End_Dat e. These columns are both of type
DATETIME. The following query calculates 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). However, when a booking spans more than one
day the query doesn't work, for example if a user has a booking that starts
on day one at 09.00 and ends at 14.30 on the next day, the query returns 3.5
hours for both days. Any help here would be greatly appreciated.

SELECT 8.5 - (SUM(((DATE_FOR MAT(B.Booking_E nd_Date, '%k') * 60 ) +
DATE_FORMAT(B.B ooking_End_Date , '%i')) - ((DATE_FORMAT(B .Booking_Start_ Date,
'%k') * 60 ) + DATE_FORMAT(B.B ooking_Start_Da te, '%i'))) / 60) AS
Available_Hours FROM WMS_Bookings B WHERE B.User_ID = '16' AND
B.Booking_Statu s <> '1' AND NOT ( '2003-10-07' <
DATE_FORMAT(Boo king_Start_Date , "%Y-%m-%d") OR '2003-10-07' >
DATE_FORMAT(Boo king_End_Date, "%Y-%m-%d") )

Thanks for your help
Nov 12 '05 #1
3 6242
Is this an _Access_ question? If an Access/Jet database, take a look in Help
at the DateDiff function.
"Shaun" <sh***@mania.pl us.com> wrote in message
news:fu******** ***********@war ds.force9.net.. .
Hi,

I have a table called Bookings which has two important columns;
Booking_Start_D ate and Booking_End_Dat e. These columns are both of type
DATETIME. The following query calculates 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). However, when a booking spans more than one
day the query doesn't work, for example if a user has a booking that starts on day one at 09.00 and ends at 14.30 on the next day, the query returns 3.5 hours for both days. Any help here would be greatly appreciated.

SELECT 8.5 - (SUM(((DATE_FOR MAT(B.Booking_E nd_Date, '%k') * 60 ) +
DATE_FORMAT(B.B ooking_End_Date , '%i')) - ((DATE_FORMAT(B .Booking_Start_ Date, '%k') * 60 ) + DATE_FORMAT(B.B ooking_Start_Da te, '%i'))) / 60) AS
Available_Hours FROM WMS_Bookings B WHERE B.User_ID = '16' AND
B.Booking_Statu s <> '1' AND NOT ( '2003-10-07' <
DATE_FORMAT(Boo king_Start_Date , "%Y-%m-%d") OR '2003-10-07' >
DATE_FORMAT(Boo king_End_Date, "%Y-%m-%d") )

Thanks for your help

Nov 12 '05 #2
Thanks for your reply, but I am using mySQL 3.23 and DATEDIFF doesn't come
out until 4.11 in mySQL...
"Larry Linson" <bo*****@localh ost.net> wrote in message
news:tH******** *********@nwrdd c01.gnilink.net ...
Is this an _Access_ question? If an Access/Jet database, take a look in Help at the DateDiff function.
"Shaun" <sh***@mania.pl us.com> wrote in message
news:fu******** ***********@war ds.force9.net.. .
Hi,

I have a table called Bookings which has two important columns;
Booking_Start_D ate and Booking_End_Dat e. These columns are both of type
DATETIME. The following query calculates 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). However, when a booking spans more than one day the query doesn't work, for example if a user has a booking that

starts
on day one at 09.00 and ends at 14.30 on the next day, the query returns

3.5
hours for both days. Any help here would be greatly appreciated.

SELECT 8.5 - (SUM(((DATE_FOR MAT(B.Booking_E nd_Date, '%k') * 60 ) +
DATE_FORMAT(B.B ooking_End_Date , '%i')) -

((DATE_FORMAT(B .Booking_Start_ Date,
'%k') * 60 ) + DATE_FORMAT(B.B ooking_Start_Da te, '%i'))) / 60) AS
Available_Hours FROM WMS_Bookings B WHERE B.User_ID = '16' AND
B.Booking_Statu s <> '1' AND NOT ( '2003-10-07' <
DATE_FORMAT(Boo king_Start_Date , "%Y-%m-%d") OR '2003-10-07' >
DATE_FORMAT(Boo king_End_Date, "%Y-%m-%d") )

Thanks for your help


Nov 12 '05 #3
I think you are trying to do too much in one query. I suggest that you do
one query to find the booking hours in each day followed by another query
that sums the days of interest.
Hugh
"Shaun" <sh***@mania.pl us.com> wrote in message
news:fu******** ***********@war ds.force9.net.. .
Hi,

I have a table called Bookings which has two important columns;
Booking_Start_D ate and Booking_End_Dat e. These columns are both of type
DATETIME. The following query calculates 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). However, when a booking spans more than one
day the query doesn't work, for example if a user has a booking that starts on day one at 09.00 and ends at 14.30 on the next day, the query returns 3.5 hours for both days. Any help here would be greatly appreciated.

SELECT 8.5 - (SUM(((DATE_FOR MAT(B.Booking_E nd_Date, '%k') * 60 ) +
DATE_FORMAT(B.B ooking_End_Date , '%i')) - ((DATE_FORMAT(B .Booking_Start_ Date, '%k') * 60 ) + DATE_FORMAT(B.B ooking_Start_Da te, '%i'))) / 60) AS
Available_Hours FROM WMS_Bookings B WHERE B.User_ID = '16' AND
B.Booking_Statu s <> '1' AND NOT ( '2003-10-07' <
DATE_FORMAT(Boo king_Start_Date , "%Y-%m-%d") OR '2003-10-07' >
DATE_FORMAT(Boo king_End_Date, "%Y-%m-%d") )

Thanks for your help

Nov 12 '05 #4

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

Similar topics

5
13272
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
4
1873
by: sah | last post by:
I need some help with the following query: DECLARE @SRV VARCHAR(20), @date smalldatetime SET @SRV = (select @@servername) SET @date = '20040901' select Srv_Name = @SRV, DB_Name = 'DB_NAME', Table_Name = 'Info_Table', Date_of_Records = @date, count(*) AS 'Actual Total' ,
9
3455
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM, VARCHAR(10) WO.PROBLEMCODE, VARCHAR(8)
5
1694
by: angelasg | last post by:
I am working with employee schedules. Each schedule is comprised of segments (shift, lunch, break, training, etc.) that have rankings. Each record has the employee id, the date the shift starts, the start and end time of each segment, the duration,the segment type and its rank. The start and end times of the schedules can overlap, but the segment that has the higher rank takes precedence. As a simple example, an employee working 8a-5p...
2
1573
by: sk | last post by:
I have a table for storing alerts (exceptional situations) occuring on devices that I monitor. Associated with each alert is an alert code, a description, the device responsible for causing the alert, when the alert was generated, and when the alert was removed (device no longer had the alert) A candidate table definition looks like CREATE TABLE Alerts ( device_id varchar(17),
5
2667
by: The Pig | last post by:
Got a table. Date Time Code 1/1/2003 1700 xbc 1/1/2003 1800 xbc 1/1/2003 1800 xbc 2/4/2004 1650 abc 2/4/2004 1700 abc The problem is I need a query that will delete rows that have the same
2
1611
by: rdraider | last post by:
Hi, We have a lame app that uses 2 datetime(8) fields, 1 stores the date, the other the time. example query: select aud_dt, aud_tm from orders results: aud_dt aud_tm
5
3103
by: Spook | last post by:
I have a SQL table with the following fields: accounts, orderid's and datetime Account OrderID Datetime 1 1 2007-03-01 09:30 1 2 2007-03-01 09:35 10 3 2007-03-01 10:30
2
1598
by: rizal123456789 | last post by:
any can help me. iam new in oracle. i have a table like this key || datetime || amount where key is varchar(7) and amount is number i want make some view that show sum of amount per a mounth and look like this
2
7258
by: Dinesh | last post by:
Hi experts, I am working on SQL server 2005 reporting services and i am getting a problem in writting a query. Situation is given below. There is one table in database Named Child Now i have to find the All childrens whoes Age is 13 years Base on
0
8177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.