Solved

VB.Net - Query to compare Datetime in SQL Server

Posted on 2013-12-27
1
507 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
[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
1 Comment
 
LVL 13

Accepted Solution

by:
Jesus Rodriguez earned 500 total points
ID: 39742716
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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