Where Conditions [C#] - DATEPART

Where Conditions [C#] - DATEPART

guidolsguidols Posts: 38Questions: 14Answers: 1
edited September 2022 in Editor

Hi,

is it possibile to use SQL functions as DATEPART in the Where Conditions?

Given this example with DATE_ADD:

editor.Where( q =>
    q.Where( "date", "DATE_ADD( NOW(), INTERVAL -14 DAY )", ">=", false );
);

I tried to modify it to use DATEPART, but without success.

The resulting query should be something like:

SELECT * FROM ... WHERE CONVERT(VARCHAR(MAX), DATEPART(year, [Date])) = '2022'

or just

SELECT * FROM ... WHERE DATEPART(year, [TransfectionDate]) = '2022'

Thanks!!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi,

    .Where(q => q.Where("DATEPART(year, start_date)", "2022"))
    

    Should do the job. I've just tested it locally and it looks good.

    Allan

  • guidolsguidols Posts: 38Questions: 14Answers: 1

    Thanks Allan!

Sign In or Register to comment.