Solved

T-SQL Time

Posted on 2012-12-20
4
274 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
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 42

Assisted Solution

by:EugeneZ
EugeneZ 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 69

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

820 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