/    Sign up×
Community /Pin to ProfileBookmark

DATETIME Format in 12 Hours

Good day!

I have 2 columns one for timein and one for timeout…and the data is from uploaded .xml file, my problem now is the saving of timeout in database..

in my .xml file I have this data:

Emp no Time In Time Out
100603 10/1/11 7:30 AM 10/1/11 6:00 PM
100603 10/2/11 8:00 AM 10/2/11 6:30 PM

and it saves in db
Emp no Time In Time Out
100603 2011-10-01 07:30:00 2011-10-01 18:00:00
100603 2011-10-02 08:00:00 2011-10-01 18:30:00

I want the timein and time out is formatted in 12 hours. As you can see the time out is formatted in 24 hours.

Thank you…

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@newphpcoderauthorOct 24.2011 — I upload .xml using php and it saves to database.

I tried this data to upload:

100603 10/1/11 5:35 AM 10/1/11 1:35 PM // this is the exact schedule of employee and its 8 hours per day he time in exactly and timeout exactly also, so no problem in computing because it is 8 hours.

100603 10/2/11 5:25 AM 10/2/11 1:55 PM //in this example data the employee time in early in his schedule and time out late.

100603 10/3/11 5:40 AM 10/3/11 1:40 PM // in this example data the employee time in is late, so even he also late to timeout theres no exemption because he late on his work.

and it saves it database:

100603 2011-10-01 05:35:00 2011-10-01 13:35:00

100603 2011-10-02 05:25:00 2011-10-01 13:55:00

100603 2011-10-02 05:40:00 2011-10-01 13:40:00




Now, I know that the data stored time in database formatted in 24 hours. Honestly, I want to accomplish is to get the total hours of the employee based on the employee no.

and I tried this code:
<i>
</i>select sec_to_time(unix_timestamp(timeout) - unix_timestamp(timein)) AS totalhours from employee;


and the result of this code is:

totalhours:

08:00:00

08:30:00

08:00:00



and the result is

the first is correct because the real schedule is 5:35 AM - 1:35 PM

the second is wrong it should be 8 hours only even he timein early and timeout late.

the third is also wrong because the employee is late to timein, even he also timeout late., it should be deduct or subtract in hours the late of employee.
Copy linkTweet thisAlerts:
@experts585Oct 24.2011 — i think you should try if else conditions for this metter
Copy linkTweet thisAlerts:
@newphpcoderauthorOct 24.2011 — How???can you give me an idea or example?I only do this internally...I mean I only run the query in database.

Thank you
×

Success!

Help @newphpcoder 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...