Eagain
Eagain

Reputation: 47

Get data for every Friday between two dates

I have a SQL-Server database in which I want to get the data from the column VL_DR between two given dates and where the date is a Friday.

"SELECT VL_DR FROM table_VL WHERE date>='" + date_start
                + "' AND date<='" + date_end
                + "' AND DATENAME(dw, date)='Friday'"

But after the request I have an empty list while I should have some values. What should I fix to get the correct request?

Upvotes: 1

Views: 5735

Answers (3)

Fred
Fred

Reputation: 5808

If its SQL Server

Try

SELECT VL_DR FROM table_VL WHERE ([date] BETWEEN date_start and date_end) AND LOWER(DATENAME(dw, [date]))='friday'

If its MySQL

Try

SELECT VL_DR FROM table_VL WHERE ([date] BETWEEN date_start and date_end) AND DAYNAME([date])='Friday'

Upvotes: 3

Richard Vivian
Richard Vivian

Reputation: 1750

This code will work, based on data in a Share Code database that I have. This is for MS-SQL.

SELECT
    CloseDate, DatePart(WEEKDAY,CloseDate) AS DAY_OF_WEEK_No , SharePrice 
FROM
    SharePrice 
WHERE
    CloseDate BETWEEN '01 October 2014' AND '31 October 2014'
AND
    DATEPART(WEEKDAY,CloseDate) = 6 -- 1=Sunday; 7=Saturday
AND
    ShareCode = 'AGL'

Upvotes: 0

Bruno Calza
Bruno Calza

Reputation: 2780

Assuming MySQL. DAYNAME should work

"SELECT VL_DR FROM table_VL WHERE date>='" + date_start
            + "' AND date<='" + date_end
            + "' AND DAYNAME(date)='Friday'"

Example:

SELECT DAYNAME('2008-05-15');

results Thursday

Upvotes: 0

Related Questions