SQL Comparison between dates

Sarvesh Pandey 71 Reputation points
2022-12-05T05:44:37.777+00:00

Hi All,
On 5th of December 2022, I have created a table with date 5/12/2022.

Now when i am running the below query it is showing no recods. Note - getdate() = 5/12/2022

Getdate() - ![266919-image.png]2

Table detail -
266950-image.png

SQL Query -
select * from BusinessDays where Convert(varchar(2),Datepart(day,getdate())) = convert(varchar(2),'Business Day');

267041-image.png

I have also use CAST function but still getting no ouputs

Developer technologies Transact-SQL
0 comments No comments
{count} votes

Accepted answer
  1. Sreeju Nair 12,666 Reputation points
    2022-12-05T06:09:55.457+00:00

    in your query, refer to the following part,

    convert(varchar(2), 'Business Day')

    Replace 'Business Day' to the column name Business Day and your query will work.

    select * from BusinessDays where Convert(varchar(2), DatePart(day, getdate())) = convert(varchar(2), [Business Day]);  
    

    Hope this helps


1 additional answer

Sort by: Most helpful
  1. NikoXu-msft 1,916 Reputation points
    2022-12-05T05:56:53.203+00:00

    Hi @Sarvesh Pandey

    Change it to this:

    select * from BusinessDays where Convert(varchar(2),Datepart(day,getdate())) = convert(varchar(2),[Business Day]);  
    

    Best regards,
    Niko

    ----------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.