Results 1 to 13 of 13

Thread: How to detect one date field value is later/greater than the other date field?

Threaded View

  1. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How to detect one date field value is later/greater than the other date field?

    If you're using .NET then you should use .NET and stop pretending that you're still using VB6. If you have a teacher or a boss who still thinks it's the 1980s then I guess you're out of luck but, otherwise, join the rest of us in 2020. Here's the same ADO.NET and pure SQL solution I provided at Stack Overflow:
    vb.net Code:
    1. Dim sql = "SELECT COUNT (*)
    2.            FROM Docstable
    3.            WHERE (Date1 >= Date2 AND Date1 BETWEEN @DateFrom1 AND @DateTo1)
    4.            OR (Date2 > Date1 AND Date2 BETWEEN @DateFrom2 AND @DateTo2)"
    5. Dim dateFrom = DatePickerFrom.Value.Date
    6. Dim dateTo = DatePickerTo.Value.Date
    7. Dim count As Integer
    8.  
    9. Using connection As New OleDbConnection("connection string here"),
    10.       command As New OleDbCommand(sql, connection)
    11.     With command.Parameters
    12.         .Add("@DateFrom1", OleDbType.Date).Value = dateFrom
    13.         .Add("@DateFrom2", OleDbType.Date).Value = dateFrom
    14.         .Add("@DateTo1", OleDbType.Date).Value = dateTo
    15.         .Add("@DateTo2", OleDbType.Date).Value = dateTo
    16.     End With
    17.  
    18.     connection.Open()
    19.  
    20.     count = CInt(command.ExecuteScalar())
    21. End Using
    Last edited by jmcilhinney; Jun 4th, 2020 at 08:13 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width