Formatting Dates in SQL Server

In SQL Server the date formatting is a bit peculiar to say the least...I used the following query to be able to go 30 days back from current date:

select cast(floor(cast(getdate()-30 as float)) as datetime)

If you know the actual date string, you can use it simply as follows:
select * from emp where dat between '2012-04-17' and '2012-04-18'

No comments: