It is possible to get difference minutes from date and time diffrence

01-21-10, 12:37 AM
|
 |
Newbie Coder
|
|
Join Date: Sep 2008
Location: coimbatore
Posts: 47
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
|
It is possible to get difference minutes from date and time diffrence
I did following coding to display date and time difference between two dates( $current_date, $data_ref). Date format is date("Y-m-d h-i-s").
$current_year = substr($current_date,0,4);
$current_month = substr($current_date,5,2);
$current_day = substr($current_date,8,2);
$current_hour = substr($current_date,11,2);
$current_min = substr($current_date,14,2);
$ref_year = substr($data_ref,0,4);
$ref_month = substr($data_ref,5,2);
$ref_day = substr($data_ref,8,2);
$ref_hour = substr($data_ref,11,2);
$ref_min = substr($data_ref,14,2);
$minutes_Diff = $ref_min-$current_min;
$hour_Diff = $ref_hour-$current_hour;
$day_Diff = $ref_day-$current_day;
$month_Diff = $ref_month-$current_month;
$year_Diff = $ref_year-$current_year;
Finally i get the date difference , Hour difference .
It is possible to calculate total minutes difference ?
|

01-21-10, 06:35 AM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
|
|
Lots of ways to do this....
You could use this, although you'll need to convert your dates to mySQL timestamps:
|

01-21-10, 03:57 PM
|
|
Aspiring Coder
|
|
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
|
|
|
|
|
The Following User Says Thank You to Jcbones For This Useful Post:
|
|

01-21-10, 08:40 PM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
|
|
I think he wanted to get the difference in seconds between two dates, unless I misread his post.
Quote:
Originally Posted by Jcbones
|
|
|
The Following User Says Thank You to End User For This Useful Post:
|
|

01-22-10, 04:29 PM
|
|
Aspiring Coder
|
|
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
|
|
I know, I was just showing an easier way to strip the time using explode(), rather than substr().
But, since you said something, I went ahead and created a function that may be useful.
Returns time difference from two timestamps. User decides calculation limits. I could take this to Years, but right now it is limited to Days and below.
|

01-22-10, 07:34 PM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
Just for fun ...
... because that way, even if the user messes up the dates, the code works.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|