Solved

T-SQL Time

Posted on 2012-12-20
4
271 Views
Last Modified: 2012-12-20
I want to verify the correct time in T-SQL 2000.
To specify today's date from 12AM until 11:59PM
Would it be specified like below?
For SET @startdate = '2012-12-20 00:00:00'
SET @enddate = '2012-12-20 23:59:59'

I want to be sure about the 23:59:59 because I found some existing queries on a SQL Server 2000 and it is displayed as 00:00:00 to 11:59:59

Thanks.
0
Comment
Question by:fjkaykr11
  • 2
4 Comments
 
LVL 42

Assisted Solution

by:EugeneZ
EugeneZ earned 250 total points
Comment Utility
try to use SQl server function
GETDATE

select GETDATE()

2012-12-20 15:36:33.620
---

see more about GETDATE() @ http://msdn.microsoft.com/en-US/library/ms188383(v=sql.105).aspx

--

in case you wish to be sure
that queries like this -try :
declare
@startdate as datetime,
@@enddate  as datetime

set @startdate = '2012-12-20 00:00:00'
SET @enddate = '2012-12-21 00:00:00'
select * from table where DT >=@startdate And DT < @Enddate
0
 
LVL 42

Assisted Solution

by:EugeneZ
EugeneZ earned 250 total points
Comment Utility
or
use Datediff function'
declare
@startdate as datetime,
@@enddate  as datetime

set @startdate = '2012-12-20 00:00:00'
SET @enddate = '2012-12-21 00:00:00'
select * from table where DATEDIFF ( day , '2012-12-20 00:00:00' , '2012-12-20 23:00:00' )=0

---DATEDIFF  http://msdn.microsoft.com/en-us/library/ms189794(v=sql.105).aspx
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 250 total points
Comment Utility
The "2012-12-20 ..." date literal format always uses and expects military time (on MSSQL).
0
 
LVL 3

Author Closing Comment

by:fjkaykr11
Comment Utility
Thanks for the help.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now