Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
date and time adding minutes
Old 01-18-2012, 03:34 PM date and time adding minutes
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Hello guys im having trouble adding 2 hours to the current time in php its not working and i dont understand why? :/ is the code wrong? please help here is the code

PHP Code:
//current time was 12:28pm
$extra1 time() + 7200;
$timet2 date('H:m:s',$extra1);

echo 
"time 2 ".$timet2."<br/>";// the output was 14:01:15 when its supposed to be 2 hours later

if($values['chapel'] == 'Yes' && $assign == '0'){
    
$strSQLInsert "insert into alert (`case_no`,`deceased_name`,`date`,`time`,`task`,`counselor`,`status`) values ('".$values['case_no']."','".$values['deceased_name']."','".$cdate."','".$timet2."','find_chapel','".$values['counselor']."','Active')";
db_exec($strSQLInsert,$conn);

}
//current time was 12:28 pm 
$extra2 time() + 8100;
$timet3 date('H:m:s',$extra2);

echo 
"time 3 ".$timet3."<br/>";// output was 14:01:15 when it was supposed to be 2 hours and 15 min later

if($values['insurance_funds'] == 'Yes' && $assign == '0'){
    
$strSQLInsert "insert into alert (`case_no`,`deceased_name`,`date`,`time`,`task`,`counselor`,`status`) values ('".$values['case_no']."','".$values['deceased_name']."','".$cdate."','".$timet3."','insurance','".$values['counselor']."','Active')";
db_exec($strSQLInsert,$conn);


stivens is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-18-2012, 04:03 PM Re: date and time adding minutes
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Could it be a timezone issue? What is the current time according to the server? Try:
PHP Code:
$extra1 time() + 60 60 2;
$timet2 date('H:m:s',$extra1);

echo 
'Now: ' date('H:m:s') . "\n";
echo 
'2 hours later: ' $timet2
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-18-2012, 04:16 PM Re: date and time adding minutes
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Could it be a timezone issue? What is the current time according to the server? Try:
PHP Code:
$extra1 time() + 60 60 2;
$timet2 date('H:m:s',$extra1);

echo 
'Now: ' date('H:m:s') . "\n";
echo 
'2 hours later: ' $timet2
timezone is PSDT...

im going crazy now!! when i run the code it was 13:01:00 the output was 15:01:00 when i refresh the page 5 min later it keeps giving me the same current time 13:01:00 even thought it is 15:06:00 :S
stivens is offline
Reply With Quote
View Public Profile
 
Old 01-19-2012, 12:07 PM Re: date and time adding minutes
orionoreo's Avatar
Ultra Talker

Posts: 335
Name: Jerry
Trades: 0
I'm personally more comfortable with timestamps:

PHP Code:
$extra1 '+2 hours';
$timet2 strtotime($extra1);
$timet2 date('H:m:s',$timet2);

$extra1 7200;
$timet2 strtotime("now") + $extra1;
$timet2 date('H:m:s',$timet2); 
The current time is your server time as well
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
orionoreo is offline
Reply With Quote
View Public Profile
 
Old 01-19-2012, 03:42 PM Re: date and time adding minutes
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
thanks guys the error was here

H:m:s the right one is H:i:s didn't noticed i did that
stivens is offline
Reply With Quote
View Public Profile
 
Old 01-21-2012, 10:23 AM Re: date and time adding minutes
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Quote:
Originally Posted by stivens View Post
thanks guys the error was here

H:m:s the right one is H:i:s didn't noticed i did that
You're not the first to be caught by that
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-21-2012, 11:37 PM Re: date and time adding minutes
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Quote:
Originally Posted by PaulW View Post
You're not the first to be caught by that
that is good to know hehehe
stivens is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to date and time adding minutes
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25901 seconds with 12 queries