Hi,
How to calculate no of days working of an employee and no of days absent in a current month.

Antony, this is a serious question...

Do you think we can give you an answer to this without knowing your database schema?

Member Avatar for diafol

Please take the time to articulate your question clearly and provide all the information that you have. Include DB schemas and any code that you've tried or are in the process of trying.

Asking this sort of ambiguous question presents contributors with problems. We are here to help, but we could be providing solutions that are not appropriate because you did not supply all the relevant details. This simply wastes our time and effort. You will not be thanked for it. We have discussed this before on other threads. Please take note of this.

The PHP forum has a great sticky:

https://www.daniweb.com/web-development/php/threads/435023/read-this-before-posting-a-question

and although it deals with PHP, the majority of it is relevant to asking questions in general. Thank you.

Assume that you have a table to track every day yours employees records with working or absent, then try the following

where er.working = 1 the employee worked the er.recordDate and er.working = 0 the employee absent

SELECT 
    er.employeeId,
    SUM(CASE
        WHEN er.working = 1 THEN 1
        ELSE 0
    END) working,
    SUM(CASE
        WHEN er.working = 1 THEN 0
        ELSE 1
    END) absent
FROM
    employeeRecords AS er
WHERE
    er.recordDate BETWEEN '$from_date' AND '$to_date'
GROUP BY er.employeeId

George

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.