I created a payroll system, and now I don't have any idea how can I sum the time of the employee in and out.
I need the Sum of Hours that the employee attendance.
I have table for the Attendance and table for the sum of hours, the data in attendance table is from the upload files .xml the format of time is 08:00:00
Do you need to store the in/out times as human-readable values like that? You could just store a unix timestamp and subtract "out" from "in" to get the number of miliseconds worked, then calculate it to hours from there.
Otherwise (if you are committed to the 08:00:00 format) you might just use strtotime() for each of your stored times and then proceed as above with your subtraction and calculation of hours.
Do you need to store the in/out times as human-readable values like that? You could just store a unix timestamp and subtract "out" from "in" to get the number of miliseconds worked, then calculate it to hours from there.
Otherwise (if you are committed to the 08:00:00 format) you might just use strtotime() for each of your stored times and then proceed as above with your subtraction and calculation of hours.
Right now I encountered problem in uploading and saving of date and time, my column date in .xml file has a format mm/dd/yyyy like for example 10/1/2011 and the time column in .xml 11:40:00 AM, 8:02:00 PM , in my code I dont know how can I save it with the same format.
The In and Out is in one field onyl the time column..
it'll reformat a date from d.m.y to a unix time stamp. its easily adjusted to suit your stuff by adjusting the sscanf() line and the $datetime = new line to suit your formatting.
you could even go one step further and join your 2x input xml strings into a single string and just reformat that entire string rather than reformatting the 2 strings separately.
__________________
A programmer is just a tool which converts caffeine into code
it'll reformat a date from d.m.y to a unix time stamp. its easily adjusted to suit your stuff by adjusting the sscanf() line and the $datetime = new line to suit your formatting.
you could even go one step further and join your 2x input xml strings into a single string and just reformat that entire string rather than reformatting the 2 strings separately.
personally I would put it in your add_employee function
post examples of your $date and $time inputs to that function (before you start doing sub str stuff) and I can knock you up a better example. and how are you storing them in the DB as separate columns or in a single column etc and what data type is the column string? datetime? timestamp?
__________________
A programmer is just a tool which converts caffeine into code
and the .xml file:
date: 10/1/2011
time: 8:00:40 AM
and it save to database:
date: 2011-10-01
time: 08:00:40
now it save in database but the time AM and PM did not display and save.and the hours become 24 hours.
The time and date field is very important for me to resolve because of computing the attendance.
Thank you
personally I would put it in your add_employee function
post examples of your $date and $time inputs to that function (before you start doing sub str stuff) and I can knock you up a better example. and how are you storing them in the DB as separate columns or in a single column etc and what data type is the column string? datetime? timestamp?
AM/PM are not supported by databases or time functions so stop using them use 24 hour if you must
also why in your xmp file are you brining out a separate date time? it would make more sense to just bring back something in the form of "dd/mm/yyyy hh:mm:ss" as just a single xml node rather than 2.
This will return your date as a unix time stamp which you can then compare against / save whatever you want to do with it do something similar with your time stamp.
I do think you're making life hard on yourself though. get your xml to sumply supply a single node back in a combined date/time stamp and you'll make your life easier
__________________
A programmer is just a tool which converts caffeine into code
The hours that save in database is formatted in 24hours. If i combined the date and time in one column in .xml how can I compute the hours per employee? and is it also in database the date and time is in one field?
I have date and time column separately...in time column the data is in and out of the employee...now I need the total sum of per employee working hours
I tried this code for the importing the .xml fiole and save to database:
PHP Code:
<?php
$data = array();
$con = mysql_connect("localhost", "root","");
if (!$con) {
die(mysql_error());
}
$db = mysql_select_db("db_upload", $con);
if (!$db) {
die(mysql_error());
}
$sql = "select * from employee";
$result = mysql_query($sql, $con);
if (!$result) {
die(mysql_error());
}
$total = mysql_num_rows($result);
if ($total > 0) {
$sql = "delete from employee";
$result = mysql_query($sql, $con);
if (!$result) {
die(mysql_error());
}
}
function add_employee($emp, $employee, $last, $mi, $date, $time)
{
global $data;
$con = mysql_connect("localhost", "root","");
if (!$con){ die(mysql_error());}
$db = mysql_select_db("db_upload", $con);
if (!$db) {
die(mysql_error());
}
Create 2 columns in your database one called start date one called end date.
Insert the variable $unixdate for both the start and end date into the selected column.
When you want to then calculate how many hours a person worked you just do end date column - start date column and it'll return you the number of seconds worked.
I'm sure you can work out how to convert from seconds into hours/minutes yourself.
__________________
A programmer is just a tool which converts caffeine into code
Create 2 columns in your database one called start date one called end date.
Insert the variable $unixdate for both the start and end date into the selected column.
When you want to then calculate how many hours a person worked you just do end date column - start date column and it'll return you the number of seconds worked.
I'm sure you can work out how to convert from seconds into hours/minutes yourself.
Actually I dont have any idea about the computation of time. And the .xml file that I have is like a excel file that was save as a .xml file...
Now I have a date and time separate column in .xml and also in my database...and the datatype of date is date and time is time.
and now here is my revise code:
PHP Code:
<?php
$data = array();
$con = mysql_connect("localhost", "root","");
if (!$con) {
die(mysql_error());
}
$db = mysql_select_db("db_upload", $con);
if (!$db) {
die(mysql_error());
}
$sql = "select * from employee";
$result = mysql_query($sql, $con);
if (!$result) {
die(mysql_error());
}
$total = mysql_num_rows($result);
if ($total > 0) {
$sql = "delete from employee";
$result = mysql_query($sql, $con);
if (!$result) {
die(mysql_error());
}
}
function add_employee($emp, $employee, $last, $mi, $date, $time)
{
global $data;
$con = mysql_connect("localhost", "root","");
if (!$con){ die(mysql_error());}
$db = mysql_select_db("db_upload", $con);
if (!$db) {
die(mysql_error());
}
$date = substr($date,0,-13); //i used substr to remove the last character, because if im not used this the data display is :2011-01-10T00:00:00.000
$time = substr($time,11,-4);
$date = strtotime($date);
$date = date('d-m-Y', $date);
$time = strftime('%I:%M %p', strtotime($time)); // i used this for 12 hours
$sql = "INSERT INTO employee (EMP_NO, Name, last, mi, date, time) VALUES ('$emp', '$employee', '$last', '$mi', '$date', '$time')";
mysql_query($sql, $con);
My question is...is it possible in my code to compute the hours per employee if my date and time is separately...because the time field has the data of time in and time out of employee.
and honestly , i felt difficulties how to compute the hours of employee and it only basic hours per day is 8...Other said that it should be the date and time is combine in one column, but i don't have idea if how can I compute the time of employee..
Thank you so much.. I hope you understand...Its my first time to do that..