0

I want to filter data by day and month only excluding the year. For example I want to find people born from day 1 to day 15 in september without including years so what i did is like...

    Private Sub ButtonFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonFilter.Click

        Dim sdate As Date = dtpfrom.Value.AddMonths(-1).AddDays(-1)
        Dim edate As Date = dtpto.Value.AddMonths(-1).AddDays(-1)
        Try
            con = New OleDbConnection(cs)
            con.Open()
            cmd = New OleDbCommand("SELECT ID, SerialNo as [Serial No], NamaLengkapdanBaptis as [Nama Lengkap], JenisKelamin as [Jenis Kelamin], NoKTP as [Nomor KTP], TempatLahir as [Tempat Lahir], TanggalLahir as [Tanggal Lahir], GolonganDarah as [Golongan Darah], AlamatLengkap as [Alamat Lengkap], NoTelp as [Nomor Telepon], PendidikanUmum as [Pendidikan Umum], IjazahTahun as [Pendidikan Umum Berijazah Tahun], PendidikanAlkitab as [Pendidikan Alkitab], IjazahAlkitabTahun as [Alkitab Berijazah Tahun], TrainingEquipping as [Training & Equipping], Pekerjaan as [Pekerjaan], NamaPerusahaan as [Nama Perusahaan], AlamatTempatKerja as [Alamat Perusahaan], TelpKantor as [Telepon Kantor], BaptisSelam as [Baptis Selam], TempatatauGereja as [Tempat atau Gereja], PelayanandiGereja as [Pelayanan di Gereja], PelayananSebagai as [Sebagai], TempatNikah as [Tempat Nikah], TanggalNikah as [Tanggal Nikah], NamaAyah as [Nama Ayah], NamaIbu as [Nama Ibu],FotoProfil as [Foto Profil], NamaLengkapdanBaptisSI as [Nama Lengkap Istri atau Suami], JenisKelaminSI as [Jenis Kelamin Istri atau Suami], NoKTPSI as [Nomor KTP Istri atau Suami], TempatLahirSI as [Tempat Lahir Istri atau Suami], TanggalLahirSI as [Tanggal Lahir Istri atau Suami], GolonganDarahSI as [Golongan Darah Istri atau Suami], AlamatSI as [Alamat Istri atau Suami], NoTelpSI as [No Telepon Istri atau Suami], PendidikanUmumSI as [Pendidikan Umum Istri atau Suami], IjazahTahunSI as [Berijazah Tahun Istri atau Suami], PendidikanAlkitabSI as [Pendidikan Alkitab Istri atau Suami], IjazahAlkitabTahunSI as [Pendidikan Alkitab Berijazah Tahun], TrainingEquippingSI as [Training & Equipping Istri atau Suami], PekerjaanSI as [Pekerjaan Istri atau Suami], NamaPerusahaanSI as [Nama Perusahaan Istri atau Suami], AlamatTempatKerjaSI as [Alamat Perusahaan Istri atau Suami], TelpKantorSI as [Telepon Kantor Istri atau Suami], BaptisanSelamSI as [Baptisan Selam Istri atau Suami], TempatatauGerejaSI as [Tempat atau Gereja Istri atau Suami], PelayanandiGerejaSI as [Pelayanan di Gereja Istri atau Suami], PelayananSebagaiSI as [Istri atau Suami Sebagai], NamaAyahSI as [Nama Ayah Istri atau Suami], NamaIbuSI as [Nama Ibu Istri atau Suami], FotoProfilSI as [Foto Istri atau Suami], NamaAnak1 as [Nama Anak 1], TanggalLahirAnak1 as [Tanggal Lahir Anak 1], SekolahAnak1 as [Sekolah Anak 1], BaptisanAnak1 as [Baptisan Anak 1], FotoProfilAnak1 as [Foto Profil Anak 1], NamaAnak2 as [Nama Anak 2], TanggalLahirAnak2 as [Tanggal Lahir Anak 2], SekolahAnak2 as [Sekolah Anak 2], BaptisanAnak2 as [Baptisan Anak 2], FotoProfilAnak2 as [Foto Profil Anak 2], NamaAnak3 as [Nama Anak 3], TanggalLahirAnak3 as [Tanggal Lahir Anak 3], SekolahAnak3 as [Sekolah Anak 3], BaptisanAnak3 as [Baptisan Anak 3], FotoProfilAnak3 as [Foto Profil Anak 3], NamaAnak4 as [Nama Anak 4], TanggalLahirAnak4 as [Tanggal Lahir Anak 4], SekolahAnak4 as [Sekolah Anak 4], BaptisanAnak4 as [Baptisan Anak 4], FotoProfilAnak4 as [Foto Profil Anak 4], NamaAnak5 as [Nama Anak 5], TanggalLahirAnak5 as [Tanggal Lahir Anak 5], SekolahAnak5 as [Sekolah Anak 5], BaptisanAnak5 as [Baptisan Anak 5], FotoProfilAnak5 as [Foto Profil Anak 5], CscArea as [CSC Area], NoCsc as [Nomor CSC], NamaGembalaArea as [Nama Gembala Area], NamaGembalaCsc as [Nama Gembala CSC] from tb_daftarjemaat WHERE [TanggalLahir] BETWEEN #" & sdate & "# AND #" & edate & "#", con)
            Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
            Dim myDataSet As DataSet = New DataSet()
            myDA.Fill(myDataSet, "tb_daftarjemaat")
            DataGridView2.DataSource = myDataSet.Tables("tb_daftarjemaat").DefaultView
            con.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

But when data retrieved, it's display from day 1 to day 15 in september also october, november, december and back again. Please help me. Thanks

2
Contributors
2
Replies
19
Views
3 Weeks
Discussion Span
Last Post by vhycko
1

You will have to change the WHERE clause to something like

WHERE DATEPART(month,TanggalLahir) = 9
  AND DATEPART(day,TanggalLahir) BETWEEN 1 AND 15

Edited by Reverend Jim

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.