PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
JPlush76
Forum Regular
Posts: 819 Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:
Post
by JPlush76 » Wed Sep 03, 2003 5:58 pm
hey all,
lets say I have a time: 3:31 PM
just like that...
how do I convert that into a usable time so I can do time differences on?
for example I have IN TIME: 3:31 PM OUT TIME: 12:54 AM
I'd want to convert those into usable time stamps so I can say the difference between your in and out time is XX hours XX minutes
anyone do anything like that before?
thanks
qads
DevNet Resident
Posts: 1199 Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane
Post
by qads » Wed Sep 03, 2003 6:00 pm
i once tried, forgot what i did but it didn't work lol....is that any help?
LOL
but yea...i'd like to know too please
Last edited by
qads on Wed Sep 03, 2003 6:01 pm, edited 1 time in total.
JPlush76
Forum Regular
Posts: 819 Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:
Post
by JPlush76 » Wed Sep 03, 2003 6:01 pm
thanks Qads! lol
qads
DevNet Resident
Posts: 1199 Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane
Post
by qads » Wed Sep 03, 2003 6:01 pm
that was quick lol
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Sep 03, 2003 8:08 pm
strtotime might help.
But without a date
Code: Select all
<?php
$sIn = '3:31 PM';
$sOut = '12:54 AM';
$nIn = strtotime($sIn);
$nOut = strtotime($sOut);
echo date('F j, Y, g:i a', $nIn), "\n", date('F j, Y, g:i a', $nOut);
?>it will get confused. On the other hand
Code: Select all
<?php
$sIn = '9/4/2003 3:31 PM';
$sOut = '9/3/2003 12:54 AM';
$nIn = strtotime($sIn);
$nOut = strtotime($sOut);
echo date('F j, Y, g:i a', $nIn), "\n", date('F j, Y, g:i a', $nOut);
?>works.
$nIn and $nOut are number of seconds since the unix epoch representing the two datetimes, so you might subtract $nIn from $nOut.
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Wed Sep 03, 2003 8:10 pm
hehe
Perhaps the following can give some more ideas?
Code: Select all
<pre>
<?php
$in = '3:31 PM';
$out = '12:54 AM';
echo strtotime($in)."\n";
echo strtotime($out)."\n";
?>
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Wed Sep 03, 2003 8:11 pm
Gah!
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Sep 03, 2003 8:19 pm
It's special mod that posts a previously stored reply the moment someone else presses the "post reply" button
just kidding
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Wed Sep 03, 2003 8:25 pm
Hahaha
You have a new message!
Do you want to overwrite the users responce with your own? Select from:
a) As is...
b) Rewrite slightly...
c) You own code, in your own words...