We help IT Professionals succeed at work.

getdate in between condition - MS SQL Server

65 Views
Last Modified: 2018-12-11
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
Comment
Watch Question

SQL Server DBA & Architect, EE Solution Guide
CERTIFIED EXPERT
Awarded 2009
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
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 ChanProblem resolver

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

Open in new window

Author

Commented:
--
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
CERTIFIED EXPERT
Awarded 2009
Distinguished Expert 2019

Commented:
>> 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 ChanProblem resolver

Commented:
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

Author

Commented:
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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions