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 1881
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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...
|
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,...
|
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...
| |