I have a SQL Server table with X being a date column defined as varchar
. I need to retrieve non-Monday days from the column. Can someone help here to retrieve the information?
- Table – Time
- Column – X
- Data Type – Varchar
Sample data in table
X
------------
2024-07-05
2024-07-08
2024-06-26
2024-06-24
2024-05-27
2024-05-20
2024-05-15
2024-05-16
Looking for the result in the same format as mentioned in the example table
Expected result:
X
----------
2024-07-05
2024-06-26
2024-05-15
2024-05-16
Can someone help me how to tackle this?
New contributor
teju rao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5
This query will help you solve that:
SELECT *
FROM your_table
WHERE DATEPART(WEEKDAY, CAST(x AS DATE)) <> 1;
Since your column x is a Varchar, you need to cast it to a Date and get the datepart.
4