Welcome to Dream.In.Code
Click Here
Getting PHP Help is Easy!

Join 117,543 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,720 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



find hour defference between two dates

 
Reply to this topicStart new topic

find hour defference between two dates

ashaajith
post 19 Jul, 2008 - 08:58 AM
Post #1


New D.I.C Head

*
Joined: 10 Jul, 2008
Posts: 22



I have 2 dates
$d2 = "12/31/2002 1:00:00 AM";
$d3 = "4/1/2002 3:15:00 AM";

How can i find the hour difference between these two dates

User is offlineProfile CardPM

Go to the top of the page


AdaHacker
post 20 Jul, 2008 - 08:43 AM
Post #2


D.I.C Head

**
Joined: 17 Jun, 2008
Posts: 112



Thanked 15 times
My Contributions


QUOTE(ashaajith @ 19 Jul, 2008 - 10:58 AM) *


How can i find the hour difference between these two dates

The easiest method is just to convert them to UNIX timestamps and subtract. That will give you the difference between the 2 in seconds, and then you can just divide by the number of seconds in whatever time span you want. For example:
php

$ts2 = strtotime($d2);
$ts3 = strtotime($d3);
# Subtract and divide by 3600 seconds/hour
$hour_diff = ($d2 - $d3) / 3600;
User is offlineProfile CardPM

Go to the top of the page

ashaajith
post 20 Jul, 2008 - 10:41 AM
Post #3


New D.I.C Head

*
Joined: 10 Jul, 2008
Posts: 22

QUOTE(AdaHacker @ 20 Jul, 2008 - 08:43 AM) *

QUOTE(ashaajith @ 19 Jul, 2008 - 10:58 AM) *


How can i find the hour difference between these two dates

The easiest method is just to convert them to UNIX timestamps and subtract. That will give you the difference between the 2 in seconds, and then you can just divide by the number of seconds in whatever time span you want. For example:
php

$ts2 = strtotime($d2);
$ts3 = strtotime($d3);
# Subtract and divide by 3600 seconds/hour
$hour_diff = ($d2 - $d3) / 3600;



thank you
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 05:41PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month