Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2004, 11:43 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare time in SQL

Hi,

I would like to compare time from a datetime cell in MSSQL with the current time. So not compare date, just time. And than get the records witch are older than the cuurent time, if you only compare time!

For example:
In the database their is a value 17/08/2004 17:03:00 and the current time is 20/10/2004 17:01:00 . Then I would like the result to be only 2 minutes.

I tried :

SELECT id FROM tTimer where DATEDIFF(minute, Convert(datetime,tijdstip,108), Convert(datetime,'" & time & "'),108) > 0

where time is 20041020 17:01:00


In fact, I want it to compare time without taking into account the date.

Is this possible with in one statement?

Thanks in advance!

 
Old October 21st, 2004, 08:55 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I found it myself. I though letting it you know.

SELECT id FROM tTimer where DATEDIFF(minute, Convert(datetime,tijdstip+DATEDIFF(day,tijdstip,Co nvert(datetime,'" & time & "',101)),101), Convert(datetime,'" & time & " " & FormatDateTime(Now(),3) & "',101)) > 0

where time is 20041020 17:01:00

In other words, I determine the difference in days between the day in the database cell and the current day. I add these to the date in the database cell. That way I can compare the two and get the difference in minutes between the two without concerning about the date.

Bey
 
Old October 21st, 2004, 05:42 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

not sure about mssql but maybe you could have done something with unique timestamp if it's built in.





Similar Threads
Thread Thread Starter Forum Replies Last Post
time in sql server is not real time hertendreef SQL Server 2005 6 April 19th, 2007 07:07 AM
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM
sql date/time keyvanjan Classic ASP Basics 5 July 22nd, 2006 03:20 PM
sql - comparing current time suzila VB.NET 2002/2003 Basics 7 May 14th, 2004 12:05 AM
Alarm Clock/How to Compare Set TIme mjwelker VB How-To 2 May 5th, 2004 05:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.