Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9162469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:13:08+00:00 2026-06-17T14:13:08+00:00

I need to get Bth working day in a month when the value of

  • 0

I need to get Bth working day in a month when the value of B is entered.
For example, If b=12 in the month of January,2013 the resultant value should be in the date format as ’17-01-2013′ as the result is calculated
after excluding Saturdays, Sundays & holidays in the month.

I have tried it in SQLserver with the following code & its working fine, but Im finding it difficult to execute it in MySql as some functions are not
available as in Sqlserver.

    Declare 
@fromDate Date,
@Daydiff int

Set @fromDate ='01 jan 2013'

Set @Daydiff=datediff(day, @fromdate, dateadd(month, 1, @fromdate))
Select * from 
(
Select 
    dateadd(day,DayNo,@fromDate) as Date,
    dateName(weekday,(dateadd(day,DayNo,@fromDate))) As WeekDate,
    Datename(month,(dateadd(day,DayNo,@fromDate))) as MonthName,
    Row_number() Over (partition by (DatePart(month,(dateadd(day,DayNo,@fromDate)))) 
    order by (dateadd(day,DayNo,@fromDate))) as Business_day
from 
    (Select top (@Daydiff) row_number() over(order by (select 1))-1 as DayNo 
     from sys.syscolumns a cross join sys.syscolumns b)Dates
Where
    dateName(weekday,(dateadd(day,DayNo,@fromDate))) Not In ('Saturday','Sunday') and
    dateadd(day,DayNo,@fromDate) Not In (Select hdate from Holidays)
)A
Where Business_day=1

Note

Holidays is the static holidays table which contains list of holidays of 2013

I need a similar instance in Mysql.
Kindly help me with this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:13:09+00:00Added an answer on June 17, 2026 at 2:13 pm

    SQLFiddle demo

    If you need first day set OFFSET 0 in the end. If the second OFFSET 1, if 15-th set OFFSET 14

    select d
    FROM
    (
    SELECT @row := @row + 1 as row,
     DATE_ADD('2013-01-01', INTERVAL @row-1 DAY) d
    from
    (SELECT @row := 0) r,
    (
    select 1 n
    union all 
    select 2 n
    union all 
    select 3 n
    union all 
    select 4 n
    union all 
    select 5 n
    union all 
    select 6 n
    ) t1,
    (
    select 1 n
    union all 
    select 2 n
    union all 
    select 3 n
    union all 
    select 4 n
    union all 
    select 5 n
    union all 
    select 6 n
    ) t2
    ) num_seq
    
    where 
    d<DATE_ADD('2013-01-01', INTERVAL 1 MONTH)
    and d not in (select hdate from Holidays )
    and DAYNAME(d) not in ('Saturday','Sunday')
    order by d
    LIMIT 1 OFFSET 20
    

    Version without OFFSET and LIMIT. See the latest where r=1 it is the 1-st day. If you need 15-th day change to where r=15

    SQLFiddle demo

    select d
    from
    (
    select d,@r := @r + 1 as r
    FROM
    (SELECT @r := 0) r1,
    (
    SELECT @row := @row + 1 as row,
     DATE_ADD('2013-01-01', INTERVAL @row-1 DAY) d
    from
    (SELECT @row := 0) r,
    (
    select 1 n
    union all 
    select 2 n
    union all 
    select 3 n
    union all 
    select 4 n
    union all 
    select 5 n
    union all 
    select 6 n
    ) t1,
    (
    select 1 n
    union all 
    select 2 n
    union all 
    select 3 n
    union all 
    select 4 n
    union all 
    select 5 n
    union all 
    select 6 n
    ) t2
    ) num_seq
    
    where 
    d<DATE_ADD('2013-01-01', INTERVAL 1 MONTH)
    and d not in (select hdate from Holidays )
    and DAYNAME(d) not in ('Saturday','Sunday')
    order by d
    ) rTable
    where r=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with a weak relation. I need get a text value
I need get a timestamp in PHP for the next day 6pm CST $tomorrow
I need get multiple values from span tags using php, for example : <div>
I am working on a website in which i need get content from iframe.
I have class Errors. I have value errorCode. I need get string by errorCode.
I need get list model from json format. I have action: [HttpPost] public ActionResult
I have a DetailsView, I need get the value specifield in DataKeyNames UserId (a
Hey guys I'm I need get a user's date of birth in a form...How
I need get browser navigator handling example. I'm using example: Imagine for many tab
I need get te value from checkbox and show in other activity and display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.