Solved

T-SQL Time

Posted on 2012-12-20
4
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 43

Assisted Solution

by:Eugene Z
Eugene Z earned 250 total points
ID: 38710999
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 43

Assisted Solution

by:Eugene Z
Eugene Z earned 250 total points
ID: 38711009
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 70

Accepted Solution

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

Author Closing Comment

by:fjkaykr11
ID: 38711847
Thanks for the help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

622 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