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.