How to retrive the data from database based on datetime in asp.net

Your database have datetime field CreatedOn
DESC- Descending  Order
ASC - Ascending Order.

MSSQL Query

select * from tablename ORDER BY CONVERT(datetime, CreatedOn) DESC;

select * from tablename ORDER BY CONVERT(datetime, CreatedOn) ASC;


For cheking Condition

select * from tablename where Status = 1 ORDER BY CASE WHEN (CONVERT(date, ClosedDae) <= GetDate())THEN 1 ELSE 0  END ASC;

No comments:

Post a Comment