Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

T-SQL Time

Posted on 2012-12-20
4
Medium Priority
?
278 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 43

Assisted Solution

by:Eugene Z
Eugene Z earned 1000 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 1000 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 71

Accepted Solution

by:
Qlemo earned 1000 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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

877 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