PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 8th, 2008, 10:57 AM
Dalixam Dalixam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 10 Dalixam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 2 sec
Reputation Power: 0
PHP5 - Need help with adding 30 minutes

Hi,

I have a time, i.e. 9.30, and I want to add 30 minutes. This is the method I have constructed:

PHP Code:
 $time_start '9.30';

$tmp explode(".",$time_start);
$tmp mktime($tmp[0], $tmp[1], 00112008);
$time_end date("G-s",strtotime("+30 mins",$tmp)); 


$time_end should output 10-00 and it does. But if the start time is different, like 11.00 then $time_end should be 11.30, but it's not, it outputs 11.00 as no calculation was done.

Can anyone point out what I'm doing wrong?

Reply With Quote
  #2  
Old May 8th, 2008, 11:11 AM
thedude2010 thedude2010 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 247 thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 35 m 10 sec
Reputation Power: 33
s is seconds
if you do this instead
PHP Code:
 $time_end=date("G-i-s"strtotime("+30 Mins"$tmp)); 

you'll see where the problem is.
i is minutes with the leading zeros

Quote:
Originally Posted by Dalixam
Hi,

I have a time, i.e. 9.30, and I want to add 30 minutes. This is the method I have constructed:

PHP Code:
 $time_start '9.30';

$tmp explode(".",$time_start);
$tmp mktime($tmp[0], $tmp[1], 00112008);
$time_end date("G-s",strtotime("+30 mins",$tmp)); 


$time_end should output 10-00 and it does. But if the start time is different, like 11.00 then $time_end should be 11.30, but it's not, it outputs 11.00 as no calculation was done.

Can anyone point out what I'm doing wrong?

Reply With Quote
  #3  
Old May 8th, 2008, 11:12 AM
b3n's Avatar
b3n b3n is offline
Dreams Abundance
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2004
Location: Prisoner of the Sun
Posts: 3,968 b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level)b3n User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 11 h 46 m 5 sec
Reputation Power: 532
Facebook
when you call date() your format string is telling it to only display hours and seconds. So the 30 minutes is never shown. So just change the format string:
PHP Code:
 $time_start '10.00';

$tmp explode(".",$time_start);
$tmp mktime($tmp[0], $tmp[1], 00112008);
$time_end date("G:i",strtotime("+30 mins",$tmp));

echo 
$time_end
__________________
.
Web Dev Cheat Sheets :: Flash 8 LiveDocs :: PHP Manual :: MySQL Manual :: My Zodiac/13Moon Mod for SMF :: Compare Game Prices

"All matter is merely energy condensed to a slow vibration. We are all one consciousness experiencing itself - subjectively. There is no such thing as death, life is only a dream. We are the imaginations of ourselves."
- Bill Hicks


"Truth is hidden in the subtle nature of the heart of everything, although it is invisible. One cannot see it from inside and neither from the surface. One can only live and experience it."
- Heart Sutra

Reply With Quote
  #4  
Old May 8th, 2008, 11:18 AM
Dalixam Dalixam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 10 Dalixam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 2 sec
Reputation Power: 0
I feel so stupid. I even double checked to make sure I had the correct format string and I still missed it.

Thanks for pointing out the error. I'll go in shame and hide in a hole

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Need help with adding 30 minutes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway