Solved

add 2 hours to php date

Posted on 2011-09-27
6
264 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now