473,407 Members | 2,312 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,407 software developers and data experts.

Adiing time (10:56:45+01:12:52)

how to add time ,the format of the time is
(00:45:55+01:22:01)
Aug 20 '07 #1
6 1585
Jeigh
73
Not sure what you're asking exactly but you can use:

Expand|Select|Wrap|Line Numbers
  1. $time = date('Y-m-d H:i:s', time());
  2. echo $time;
  3.  
This will display somthing like 2007-08-20 09:27:05

Edit:

Or are you asking how to add time together, as in 2:00 + 5:00 = 7:00, except in the format you posted? (I think this is what you're asking)

I'm not sure how to do this, but at a guess maybe you could explode the time at the colon, then adding them together normally using PHP (just like using 2 + 3) Then display it using somthing like:

$hours : $minutes : $seconds

But my knowledge of PHP is very limited and I assume there is a much easier way of doing this.
Aug 20 '07 #2
ok thanks.After exploding the time format ,how i will get the desire result?
Aug 20 '07 #3
Jeigh
73
I'd do somthing like the following:

Expand|Select|Wrap|Line Numbers
  1. $time = explode(":", *time string here*);
  2.  
  3. $hours = $time[0];
  4. $minutes = $time[1];
  5. $seconds = $time[2];
  6.  
  7. $time2 = explode(":", * second time string here*);
  8.  
  9. $hours2 = $time2[0];
  10. $minutes2 = $time2[1];
  11. $seconds2 = $time2[2];
  12.  
  13. $new_hours = $hours + $hours2;
  14. $new_minutes = $minutes + $minutes2;
  15. $new_seconds = $seconds + $seconds2;
  16.  
  17. echo "$new_hours:$new_minutes:$new_seconds";
  18.  
As far as I can see that would work but I think I may have made a simple problem 10x harder than it needed to be, I tend to overcomplicate things sometimes, but I don't know what the correct way to do it would be :P
Aug 20 '07 #4
Purple
404 Expert 256MB
Hi,

can I suggest you take a read of the time() function in the php manual.

This function returns a timestamp based on the Unix epoch - simply the number of seconds since January 1 1970 00:00:00. You can increment and decrement this by adding and subtracting the number of seconds to achieve you desired date and time.

so if now is 10:56:45, you would add and then format the output using the date()

[PHP]$newtime = time() + (01*60*60)+(12*60)+52;
echo date("F j, Y, g:i a",$newtime); [/PHP]

as an aside, you could also do it using mktime() function

Regards Purple
Aug 20 '07 #5
ronnil
134 Expert 100+
instead of splitting the string, you could also use strtotime (or strftime) add the two unixtime values together and encode it again with date()

personally i keep everything in unixtime until i have to echo it to the user.... makes it a lot easier to work with :)
Aug 20 '07 #6
thanks the problem got solved
Aug 21 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dan glenn | last post by:
Say, I want to set a cookie and have it expire an hour after it's set. It's looking like this is only possible for browsers which are in the same time zone as my server?? In other words, if I...
10
by: Yang Li Ke | last post by:
Hi guys, Im about to build a script which will log visitor time spent on my website. I got a few ideas about this, maybe checking visitors ip and storing that info in db with time in and then...
1
by: Bathroom_Monkey | last post by:
I've got a newb question about Daylight Savings Time (DST). First of all here is some server info: Apache 1.3.28 PHP 4.3.6 MySQL 3.23.49 Time is set to GMT My goal is to be able to...
0
by: Ed Bick | last post by:
Well, I read today about how I could set the dropdown value to False to change the control from presenting a Calendar to cycling through the times. Before getting that, I developed a custom Time...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
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: 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...
0
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.