Solved

add 2 hours to php date

Posted on 2011-09-27
6
266 Views
Last Modified: 2012-05-12
How can I add 2 hours to this.

<?php echo date("g:ia", strtotime($row_event['evn_entry_date'])); ?>
0
Comment
Question by:Luey
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 36711064
<?php 

echo date("g:ia", strtotime('+2 hours', $row_event['evn_entry_date'])); 

?>

Open in new window

0
 

Author Comment

by:Luey
ID: 36711125
@Rik-Legger
That changed all the times to 9:33 pm no matter what was in the data.
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 36711168
Ok sorry,
forgot to mention that $row_event['evn_entry_date'] should be a unix timestamp.

This would work:

echo date("d-m-Y H:i:s", strtotime('+2 hours', strtotime($row_event['evn_entry_date'])));

Open in new window


0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Luey
ID: 36711185
2011-09-26 10:12:46  This is what my timestamp looks like in my data.  How do I know what kind it is.
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 250 total points
ID: 36711305
Is this example not working for you?

echo date("d-m-Y H:i:s", strtotime('+2 hours', strtotime($row_event['evn_entry_date'])));

Open in new window

0
 

Author Closing Comment

by:Luey
ID: 36711392
Now i got it.  I was only trying to echo the hour and min.  When I tried to change your code i made a slight error the first time. Here is what I ended up with to echo just the hour and min and the 2 hours. In case someone needs the reference.
<?php echo date("g:ia", strtotime('+2 hours', strtotime($row_classified['cls_entry_date']))); ?>
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question