Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

add 2 hours to php date

Posted on 2011-09-27
6
Medium Priority
?
279 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

971 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