|
-
Oct 7th, 2007, 02:57 AM
#1
Date issue
Hai friends,
i just want to calculate employee work hours.
i use the following method and work well it seems.
is this method i am using is professional php way? if not, please tell what type of problem can be occour?
example :
Code:
$timein=09:10:00;
$timeout=22:20:00;
$workhrs=$timeout-$timein;
-
Oct 7th, 2007, 03:31 AM
#2
Re: Date issue
I don't know what PHP version you're using, but that code is invalid.
There is no date literal syntax.
This'll work in most newer versions:
PHP Code:
$timein = strtotime('09:10:00');
$timeout = strtotime('22:20:00');
$workhrs = strftime('%I:%M:%S', $timeout - $timein);
echo $workhrs;
Note that PHP versions 5.1.0 and above running in strict standards mode will throw a warning if no default time zone is set before using any of the date/time functions. You can set this in php.ini, or using the date_default_timezone_set function.
-
Oct 7th, 2007, 03:45 AM
#3
Re: Date issue
 Originally Posted by penagate
I don't know what PHP version you're using, but that code is invalid.
There is no date literal syntax.
This'll work in most newer versions:
PHP Code:
$timein = strtotime('09:10:00');
$timeout = strtotime('22:20:00');
$workhrs = strftime('%I:%M:%S', $timeout - $timein);
echo $workhrs;
Note that PHP versions 5.1.0 and above running in strict standards mode will throw a warning if no default time zone is set before using any of the date/time functions. You can set this in php.ini, or using the date_default_timezone_set function.
Pana, thanks for the codes. before i try it,
actually my php version is 4.4.4
my date substraction code in the first post really works
i dont no y.
ill try your code. it seems the professinal method.
-
Oct 7th, 2007, 03:47 AM
#4
Re: Date issue
I didn't know it worked in 4.4. I tried it in 6 and it didn't, so it's probably deprecated and should be avoided.
-
Oct 7th, 2007, 03:52 AM
#5
Re: Date issue
ok
-
Oct 7th, 2007, 04:12 AM
#6
Re: Date issue
pana
in
Code:
$workhrs = strftime('%I:%M:%S', $timeout - $timein);
what is '%I:%M:%S' tells? what is the usage of % sign in php?
please.
-
Oct 7th, 2007, 04:23 AM
#7
-
Oct 7th, 2007, 04:31 AM
#8
Re: Date issue
strftime(), yes now i undestood pana,
i ll come back.
-
Oct 7th, 2007, 09:07 AM
#9
Re: Date issue
pana, i have some problem with your code. it shows invalid tot hours.
time_in | time_out | total_hours
08:00:00 | 16:00:00 | 3
Code:
$temp_time_in=strtotime($timein);
$temp_time_out=strtotime($timeout);
//calculate total hours of work
$tothr = strftime('%I', $temp_time_out - $temp_time_in);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|