Click here to Skip to main content
13,152,063 members (39,483 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi everyone,

I have one windows application in which i have to select date range from my access database. What i want to do is I want to select a range in which the Birthday's of my friends lies (i.e birthday's falls in this range) so i need to select only date and month, here nothing to do with year. Below is my code

cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & Application.StartupPath & "\EDS.accdb"
       'Dim mstrFormTim As String
       Dim date1, date2, month1, month2, dat1, dat2, mon1, mon2 As String
       Dim dt1, dt2 As String
       date1 = DateTimePicker1.Value.Date
       date2 = DateTimePicker2.Value.Date
       dat1 = DatePart("d", date1)
       If dat1.Length = 1 Then
           dat1 = "0" & dat1
       End If
       dat2 = DatePart("d", date2)
       If dat2.Length = 1 Then
           dat2 = "0" & dat2
       End If
       mon1 = DatePart("M", date1)
       If mon1.Length = 1 Then
           mon1 = "0" & mon1
       End If
       mon2 = DatePart("M", date2)
       If mon2.Length = 1 Then
           mon2 = "0" & mon2
       End If
       dt1 = dat1 & "-" & mon1
       dt2 = dat2 & "-" & mon2
       mStrFinalQuery = "select Name, DOB from DateofBirth where format(DOB,""dd-MM"") between '" & dt1 & "' and '" & dt2 & "'"
       cmd = New OleDbCommand(mStrFinalQuery, cn)

here I am getting the wrong data, anyone can help me??
Posted 11-Jul-12 23:06pm
Updated 11-Jul-12 23:19pm
iamsupergrasya 12-Jul-12 5:13am
i just want to clarify the name of the table is DateofBirth?
ckulasekaran 12-Jul-12 7:42am
Check datetimepicker's date format
ryanb31 12-Jul-12 8:26am
Look at what mStrFinalQuery ends up to be. Run it in SQL management studio and figure out where the issue is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170924.2 | Last Updated 12 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100