• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 627
  • Last Modified:

VB.Net - Query to compare Datetime in SQL Server

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
Jimbo99999
Asked:
Jimbo99999
1 Solution
 
Jesus RodriguezIT ManagerCommented:
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now