Jump to content

need help in getting the equivalent month of week


newphpcoder

Recommended Posts

Hi..

 

I have 2 tables for week and calendar days.

 

first I have so_week

fields:

from_week

to_week

 

second is calendar_days

fields:

month_name

working_days

 

sample data:

from_week : 33

to_week: 36

 

month_name:

Jan

Feb

Mar

Apr

May

and so on

 

working_days:

23

22

25

25

23

 

now I need to get the working days based on from_week to week

 

for example from 33 to 36 the month is aug, sep, sep, sep i need to get the working days for that month.

 

any help is highly appreciated..

 

Thank you so much

Link to comment
Share on other sites

You are making life hard for yourself holding working days by month and working with weeks that not align to those months.

 

If I were you I'd create a table of holiday dates eg

 

+------------------+-----------------------+

|  Date            |  Holiday            |

+------------------+-----------------------+

|  2012-01-01      |  New Year            |

|  2012-04-06      |  Good Friday        |

|  2012-04-09      |  Easter Monday      |

|  2012-05-07      |  Mayday Holiday      |

|  2012-05-08      |  Jubilee Holiday    |

|  2012-08-27      |  Late Summer Holiday |

|  2012-12-25      |  Christmas Day      |

|  2012-12-26      |  Boxing Day          |

+------------------+-----------------------+

 

Then

 

SELECT w.from_week, w.to_week,
  (w.to_week  - w.from_week + 1) * 5 -
  (SELECT COUNT(*) FROM holiday
   WHERE WEEK(hol_date) BETWEEN w.from_week AND w.to_week) 
   as workdays
FROM so_week w;

 

Which gives this with my dates

 

+-----------+---------+----------+

| from_week | to_week | workdays |

+-----------+---------+----------+

|        17 |      20 |      18 |

|        33 |      36 |      19 |

+-----------+---------+----------+

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.