Solved

add 2 hours to php date

Posted on 2011-09-27
6
265 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change password links 7 74
Should I use subdomains or addon domains? 3 39
Access Object's Property 9 22
str_replace not working in php script 4 14
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

863 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

23 Experts available now in Live!

Get 1:1 Help Now