/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] string to time

Hi all,
How do I convert a string to a time ?
say i have $time_start=”18:12″ and $time_stop=”19:52″
How i can know the different between start and stop time.

Thanks for any reply ?

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachOct 20.2006 — i would do it the following way
[code=php]
$time_start="18:12";
$time_stop="19:52";

$time_start_array = explode(':',$time_start);
$time_stop_array = explode(':',$time_stop);

$start = mktime($time_start_array[0],$time_start_array[1],'00','0','0','0');
$stop = mktime($time_stop_array[0],$time_stop_array[1],'00','0','0','0');

$time = $stop-$start;

echo date('h:m',$time);
[/code]


P.S. No idea if the code will work. Haven't tested it
Copy linkTweet thisAlerts:
@b1122authorOct 20.2006 — Thanks for your reply. but it not work, the result is 01:01.

Should be 01:40 right ?
Copy linkTweet thisAlerts:
@stephan_gerlachOct 20.2006 — this one works. its tested now.

[code=php]
$time_start="19:12";
$time_stop="01:13";

$time_start_array = explode(':',$time_start);
$time_stop_array = explode(':',$time_stop);


$start = mktime($time_start_array[0],$time_start_array[1],'01','01','01','1999');
$stop = mktime($time_stop_array[0],$time_stop_array[1],'01','07','01','1999');

$time = $stop-$start;
echo date('H:i',$time);

[/code]
Copy linkTweet thisAlerts:
@b1122authorOct 20.2006 — this one works. its tested now.

[code=php]
$time_start="19:12";
$time_stop="01:13";

$time_start_array = explode(':',$time_start);
$time_stop_array = explode(':',$time_stop);


$start = mktime($time_start_array[0],$time_start_array[1],'01','01','01','1999');
$stop = mktime($time_stop_array[0],$time_stop_array[1],'01','07','01','1999');

$time = $stop-$start;
echo date('H:i',$time);

[/code]
[/QUOTE]


Dear Stephan,

Thanks a lot. Yes it work.
Copy linkTweet thisAlerts:
@pcthugOct 20.2006 — Marked Resolved.
Copy linkTweet thisAlerts:
@b1122authorOct 25.2006 — Hi all/ Stephan,

After I got the time in hours and minutes.

If I want to multiple the result by 1.5 how I do it ?

say the result is 00:40.

if i multiple 2 is correct to become 01:20

but if i multiple 1.5, it become 13:00 rather then 01:00

thanks for any help/ reply
Copy linkTweet thisAlerts:
@so_is_thisOct 25.2006 — 13:00 on a 24-hour clock equals

01:00 on a 12-hour clock.
Copy linkTweet thisAlerts:
@b1122authorOct 25.2006 — 13:00 on a 24-hour clock equals

01:00 on a 12-hour clock.[/QUOTE]


Thanks for the reply.

ok, i understand the concept.

How about if the accumulation of the result is more then 24:00.

because i got the result in this format date('H:i',$time).

If the $time more then 24:00(say 24 hours 10 minutes) , i got 00:10
Copy linkTweet thisAlerts:
@so_is_thisOct 25.2006 — I noticed in one of the original posts that the date portion must have been typoed:
[CODE]$start = mktime($time_start_array[0],$time_start_array[1],'01','01','01','1999');
$stop = mktime($time_stop_array[0],$time_stop_array[1],'01',[COLOR=Red]'07'[/COLOR],'01','1999');[/CODE]
×

Success!

Help @b1122 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...