DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Date Comparison

  1. #1
    Join Date
    Feb 2005

    Date Comparison

    Hi everyone,

    I need to know a couple of things regarding dates. First of all, where do I get a date that is universal when someone enters an entry into my database that tells the date that they entered (time is not important). I don't think I can rely on the system date because this can be altered to suit the needs of the person submitting the entry, unless there is a way to use the date of the system the database is located at. Anyways, the next thing I need to know is how to compare the date that is entered with two other dates that are stored in a database (under the date/time format). The user will enter an entry and if the date of that entry is between the beginning date for submission and the end date of submission, then the entry will be permitted, otherwise it will be tossed out. I'm sorry for bugging everyone but I have no idea how to approach this problem and my web research hasn't yielded anything, so any help would be appreciated. Thanks in advance.

    - Joe

  2. #2
    Join Date
    Nov 2003
    Portland, OR
    If you're using SQL Server, you can use the GetDate() function to obtain the date on the server. If you're using MS Access, use the Date() function. In either case, you should be able to use < and > to compare dates in SQL.
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2005
    Okay, I tried that and for some reason the dates are not being recognized. I think I may have coded the syntax incorrectly, or I am not properly calling the functions I have put in. If someone could please look over my code and tell me where I am going wrong I would appreciate it. Thanks in advance.

    - Joe


    Sub BtnSendClicked(Sender as Object, e as EventArgs)

    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Request.MapPath("CPP_v6.mdb") & ";"
    Dim MyConn as New OleDBConnection (strConn)
    Dim MySQL As String
    Dim NewSQL As String

    Dim intCount as Integer
    NewSQL = "SELECT COUNT(*) FROM FROM Dates WHERE Date() > Start.Date AND < End.Date"
    MYSQL = "SELECT COUNT(*) FROM Eligible WHERE StudentID= '" & StudentID.Text & "'"
    Dim cmd as New OleDBCommand (MySQL, MyConn)
    MyConn.Open ()
    intCount = cmd.ExecuteScalar()
    MyConn.Close ()
    Response.write("<h2>The value for intCount is " & intCount & ". Which means the record exists</h2>")

    If NOT intCount > 0 Then



    MySQL = "INSERT INTO LotteryEntry (NetworkID, StudentID, FirstName, LastName, DayPhone, EveningPhone, CellPhone, Address1, Address2, AptNumber, City, State, Zip, Email, Handicap) VALUES ('" & NetworkID.Text & "','" & StudentID.Text & "','" & FirstName.Text & "','" & LastName.Text & "','" & DayPhone.Text & "','" & EveningPhone.Text & "','" & CellPhone.Text & "','" & Address1.Text & "','" & Address2.Text & "','" & AptNumber.Text & "','" & City.Text & "','" & State.selectedItem.value & "','" & Zip.text & "','" & Email.text & "','" & Handicap.selectedItem.value & "')"

    cmd = New OleDBCommand (MySQL, MyConn)
    MyConn.Open ()
    intCount = cmd.ExecuteScalar()
    MyConn.Close ()
    End If

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.