Solved

VB.Net - Query to compare Datetime in SQL Server

Posted on 2013-12-27
1
444 Views
Last Modified: 2014-01-11
Good Day Experts!

I struggle much with comparing dates from my SQL Server db.  

I have 2 tables with date fields.  One is smalldatetime/4 with no time 2013-12-17 00:00:00. The other is datetime/8 with time 2013-12-17 07:19:04.300.

Field 1 does not get populated with the time.  So, when I compare the 2 fields if the dates are the same I need Field 2 to be greater since it has a time on it.

Can I do that? Do you have any resource sites that can help me achieve this?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
1 Comment
 
LVL 13

Accepted Solution

by:
Jesus Rodriguez earned 500 total points
Comment Utility
Do a datediff DateDiff(MM.@date1,@Date2) and if is >0 then Daate1>Date2

look this example
SELECT DATEDIFF(MINUTE,'2011-09-23 18:03:23','2011-09-23 17:15:30')

For more info look and run this query in your sql and you will see

select cast(getdate() as datetime)
select cast(getdate() as date)
SELECT DATEDIFF(MINUTE,cast(getdate() as date),cast(getdate() as datetime))

You can replace the getdate() function with Table1.Field1 for the first getdate() and Table2.Field1 for the second getdate()
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now