Solved

VB.Net - Query to compare Datetime in SQL Server

Posted on 2013-12-27
1
495 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Schema 6 45
vb.net convert long time to mm:ss 23 21
ModalPopup  question 22 38
VB.Net  Exporting Excel Woorkbook to PDF 7 59
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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