Best forum for MySQL expertise
I have a table called pay.
It has a column called date with many yyyy-mm-dd records.
I wish to test pay.date with the following MS Excel VBA function and then insert the result of the function in another column called week.
I would be very grateful for an implementation in MySQL so i can run it in HeidiSQL.
Which is the best forum for MySQL ?
Function Week_w(av)
Dim dd, fy, m, y, d
m = Month(av)
y = Year(av)
d = Day(av)
fy = y
If m * 100 + d < 406 Then fy = fy - 1
dd = DateSerial(y, m, d) - DateSerial(fy, 4, 6)
week_w = Int(dd \ 7 + 1)
End Function
Kez
I guess your week column shall contain the week number (1-53)? In that case it's so easy you should not store that redundant data into a new column, just select date with a format function when you need the week:
SELECT DATE_FORMAT(`date`, '%u') FROM pay
SELECT DATE_FORMAT(`date`, '%u') FROM pay
%U Week (00..53), where Sunday is the first day of the week
%u Week (00..53), where Monday is the first day of the week
%V Week (01..53), where Sunday is the first day of the week; used with %X
%v Week (01..53), where Monday is the first day of the week; used with %x
Please login to leave a reply, or register at first.