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
DatabasesMicrosoft SQL ServerSQL

Avatar of undefined
Last Comment
Thean S

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Raja Jegan R

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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
Peter Chan

Try
select * from tab0 where CONVERT(varchar,datecolumn,112)=CONVERT(varchar,getdate(),112)

Open in new window

Thean S

ASKER
--
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Raja Jegan R

>> 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..
Peter Chan

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

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.