I have a bunch of events which I extract from my database, some of these events extend over a night, some take place during a single day.
In the database I have the start/end times of the event, and I am trying to calculate the length of the event.
I've tried a ton of stuff, but I can't seem to get this working properly. If an event lasts from 10pm, Dec 2nd to 5am Dec3, I want it to return 7 hours.
Here's the code as I have it now. -
list($year2, $month2, $day2) = split('[/.-]', $row3['startDate']);
-
list($hour2, $min2, $sec2) = split(':', $row3['startTime']);
-
$startAll = date('H:i:s, d-m-Y', mktime($hour2,$min2,$sec2, $month2, $day2, $year2));
-
-
list($year3, $month3, $day3) = split('[/.-]', $row3['endDate']);
-
list($hour3, $min3, $sec3) = split(':', $row3['endTime']);
-
$endAll = date('H:i:s, d-m-Y', mktime($hour3,$min3,$sec3, $month3, $day3, $year3));
-
-
$length = date('H:i', $endAll-$startAll);
-
-
echo $length.'<br />'.$startAll.'<br/>'.$endAll;
-
This should be simple, but maybe it isn't
Thanks
Pete
1 1893
I'm answering my own thread here in the hope of helping somebody in the future.
previously I was trying to subtract an entire date/time range and it wasn't working for me.
Instead, I have converted the date/time to seconds and then subtract one from the other, then convert the result to hours. Pretty simple actually. -
list($year2, $month2, $day2) = split('[/.-]', $row3['startDate']);
-
list($hour2, $min2, $sec2) = split(':', $row3['startTime']);
-
$startAll = date('U', mktime($hour2,$min2,$sec2, $month2, $day2, $year2));
-
-
list($year3, $month3, $day3) = split('[/.-]', $row3['endDate']);
-
list($hour3, $min3, $sec3) = split(':', $row3['endTime']);
-
$endAll = date('U', mktime($hour3,$min3,$sec3, $month3, $day3, $year3));
-
-
$length = ($endAll-$startAll)/(60*60);
-
I hope somebody finds this useful.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ajay |
last post by:
hi!
i am reading a file on the Web. How can i find out when it was last
modified?
thanks
|
by: brettr |
last post by:
When I reference document.cookie, there is a long string of key=value;
pairs listed. I may have 100 hundred cookies on my hard drive.
However, most only have one key=value pair. Does the document.cookie
variable combine all cookie key=value pairs?
All of the examples I've seen discuss referencing a specific cookie. I
don't see how this is done.
Cookies are usually named by the domain. If I want to reference a
specific cookie, do I...
|
by: deko |
last post by:
I need to associate a Creation Date and a Modified Date with each entry in
my database. How to do this?
Here's what I've tried:
1) Use a separate table (tblUpdate) with Created, Modified, and Entry_ID
fields that has a One-To-Many relationship with the main table (tblMain -
the "one" side of the relationship) which holds all the names, addresses,
etc.
|
by: Mark Reed |
last post by:
Hi all,
I have a query (query1) which shows scan date, scan time & operator. One
scan = 1 record. What I want to do is create a report based on query 2 from
query1 which shows all the scans AND the difference between each scan.
Something like below. I have spent days on this and can't figure it out.
Date Time Login Diff
04-Dec-03 23:33:12 27478
04-Dec-03 23:33:38 27478...
|
by: Trey |
last post by:
I am trying to make a database for tracking calls, the caller gets one free
call (per 12 months), then is charged a flat fee for every call after the
first call in a 12 month time span. The data is imported into the database
weekly (about 120 calls a week) from a text file. I am able to query the
12-month part. But I am having trouble making a statement/macro/query to
check for duplicate entries with the same address in the database, with a...
| |
by: pruebauno |
last post by:
I am currently working on a tricky problem at work. I googled around a
bit, but "time intervals" did not come up with anything useful.
Although I have some rough idea of how I could solve it, I still would
value some input.
I have information of (It has only couple dozen entries.)
ServiceNum, DollarCost
and a input database table in the form (several GBytes):
ClientNumber (CN), BeginDate(BD), EndDate(ED),
|
by: pb648174 |
last post by:
Whenever I want help on a query, I get told my design is wrong, So this
time I'm posting a message during the design phase: How am I going to
perfectly design the following?
We want to be able to track time for users for multiple modules, for
now a Schedule module and a Punchlist module. These modules already
exist and there are dozens of other modules which we will add to the
list as well, two or three at a time - so it should be...
|
by: Extremest |
last post by:
Here is the code I have so far. It connects to a db and grabs headers.
It then sorts them into groups and then puts all the complete ones
into another table. Problem I am having is that for some reason now it
is not finding ones that are single posts. Here is an example of a
header for a single.
(Ask the Dust ) - "atd-ftc-repack.nfo" www.ctjes.com (1/1)
(1/1) at the end means it is part 1 of a 1 part post.
Any help would be...
|
by: =?Utf-8?B?YjF1Y2VyZWU=?= |
last post by:
Hi, still very new to programming but am a little stumped by how to do this
idea i have.
I need to make a moving average which takes every nth value in a data series
to build a running total which can then be divided by the length of the
moving average. The data series will be gaining a new value every x amount of
time t so the average has to be made from the last added value. And i also
need a way to use this same moving average but...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |