Solved

T-SQL Time

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL: Wrong Result 7 39
What does "Between" mean? 6 48
Rewriting a simple query 2 34
Generate list for insert to sql list 44 11
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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…
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.
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…

751 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