locked
select only the month and year from datetimepicker RRS feed

  • Question

  • hello?

    can anyone please help me to select only the Month and Year and show in ListView 

    i use this code but it doesnt show anything:

     Public Sub monthlyloadall()
            monthlylv.Items.Clear()
            Dim table As New DataTable
            Dim ds As New DataSet
            Dim selectedDate = BunifuDatepicker2.Value()
            Dim startDate = New Date(selectedDate.Year, selectedDate.Month, 1)
            Dim endDate = startDate.AddMonths(1)
            ds.Tables.Add(table)
    
            Dim cmd As New MySqlCommand("select item,description,price,category,date,Mode, sum(qty),sum(total)from tbl_records where  `Date` >= @StartDate AND `Date` < @EndDate group by item,description,category,date,Mode order by Mode ASC", con)
            cmd.Parameters.AddWithValue("@StartDate", startDate)
            cmd.Parameters.AddWithValue("@EndDate", endDate)
            Dim adapter As New MySqlDataAdapter(cmd)
            adapter.Fill(table)
            Dim row As DataRow
    
            For Each row In table.Rows
    
                monthlylv.Items.Add(row.Item(0))
                monthlylv.Items(monthlylv.Items.Count - 1).SubItems.Add(row.Item(1))
                monthlylv.Items(monthlylv.Items.Count - 1).SubItems.Add(row.Item(2))
                monthlylv.Items(monthlylv.Items.Count - 1).SubItems.Add(row.Item(6))
                monthlylv.Items(monthlylv.Items.Count - 1).SubItems.Add(row.Item(7))
                monthlylv.Items(monthlylv.Items.Count - 1).SubItems.Add(row.Item(5))
                monthlylv.Items(monthlylv.Items.Count - 1).SubItems.Add(row.Item(4))
            Next
    
        End Sub

    my datetimepicker code is :

    Private Sub BunifuDatepicker2_onValueChanged(sender As Object, e As EventArgs) Handles BunifuDatepicker2.onValueChanged
            If BunifuDatepicker2.Value.Day <> 1 Then
                BunifuDatepicker2.Value = DateSerial(BunifuDatepicker2.Value.Year, BunifuDatepicker2.Value.Month, 1)
            End If
           
        End Sub
    can anyone please help me? THANK YOU!

    Friday, September 14, 2018 2:56 PM

Answers

  • Hi

    Here is some code that puts the date from a datetimepicker into a textbox, formatted as Long Month Year (short month tear format shown also), on Button1 click.

    Option Strict On
    Option Explicit On
    Public Class Form1
    
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
        ' Long month
        TextBox1.Text = DateTimePicker1.Value.ToString("MMMM yyyy")
    
        ' Short month
        '   TextBox1.Text = DateTimePicker1.Value.ToString("MMM yyyy")
    
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    • Marked as answer by euchan09 Saturday, September 15, 2018 10:14 AM
    Friday, September 14, 2018 3:26 PM