Link to home
Start Free TrialLog in
Avatar of Thean S
Thean S

asked on

getdate in between condition - MS SQL Server

Hi

Can you please tell me how to use getdate:00:00:00 and getdate:11:59:00 in SQL between condition

select count(*) from tablename where createdon between 'getdate:00:00:00' and 'getdate:11:59:00'

thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Thean S
Thean S

ASKER

Thanks Raja, I will check query...

I have another issue with count that I have raised in below link. Can you please help me to fix my problem.

Link: https://www.experts-exchange.com/questions/29128960/help-required-on-MS-SQL-query.html?headerLink=workspace_open_questions

Subject: help required on MS SQL query
Try
select * from tab0 where CONVERT(varchar,datecolumn,112)=CONVERT(varchar,getdate(),112)

Open in new window

Avatar of Thean S

ASKER

--
>> CONVERT(varchar,datecolumn,112)

This one will make the indexes to go for scan instead of seek if any available on that particular column..
hence this will have some performance issues.

>> I have another issue with count that I have raised in below link

Sure, let me check now..
Try the way below to trucate the date by removing the time:
select * from tab0 where CONVERT(DATETIME, CONVERT(DATE, datecolumn))=CONVERT(DATETIME, CONVERT(DATE, GETDATE()))

Open in new window

Avatar of Thean S

ASKER

Hi Raja and HuaMin Chen,

Thanks for your help on this.

I have raised another question for my issue. Can you please help on this.

https://www.experts-exchange.com/questions/29129054/Problem-with-SQL-command-MS-SQL-Server.html?headerLink=workspace_open_questions