Example of Date Queries in MSSQL database

We can collect records based on various functions based on date field. Date Query examples

Getting records of today

select * from dt where issue_dt = GETDATE()

In our library issue table we have a issue date, so we can use this to list all books issued today Let us find out number of days passed since the issue date for all the books

select datediff(dd,issue_dt,GETDATE())as diff, issue_dt from dt

We will try to list this in order of highest number of days to lowest number of days by using order by

select datediff(dd,issue_dt,GETDATE())as diff, issue_dt from dt order by diff desc

Last 15 days record

We can get the recods of last 15 days from current day like this.

select * from dt where datediff(dd,issue_dt,GETDATE()) < 15

We can change the above query and get desired result in Month or Years .

Number of User Comments : 1



SELECT * FROM icici_cus_data where created_date = '%2021-02-24%';

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer