Home Custom format for datetime doesn't work after I change my system time
Reply: 0

Custom format for datetime doesn't work after I change my system time

user2169 Published in May 27, 2018, 3:36 am

I am trying to output some SQL queries onto a DataGridView using date constraints from the DateTimePicker

I set my custom date format during form load sub and also in the properties menu from the .vb[design] file.

However, when I run the application it automatically switches the DateTimePicker value from my custom format (yyyy-MM-dd) to Windows system format which is currently set to (m/dd/yy) or whatever format I select in Windows. This is causing problems because the application works when I switch my windows date time format to yyyy-MM-dd, however, if an end-user uses (m/dd/yy) format my application can't grab data from the SQL server.

The SQL Server format is (yyyy-MM-dd)

Private Sub Navs_Load(Sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    DTPTansAct.Value = Today.AddDays(-1)
    DTPTransAct.Format = DateTimePickerFormat.Custom
    DTPTransAct.CustomFormat = "yyyy-MM-dd"
End Sub

Private Sub BtnTransActDL_Click(sender As Object, e As EventArgs) Handles BtnTransActDL.Click
    Dim RecordCount = 0
    Dim Exception = ""

    Dim DLCmd As New MySqlCommand
    Dim DLConn As New MySqlConnection
    DLConn.ConnectionString = connectionstring.text

    Dim DLDA As New MySqlDataAdapter
    Dim DLDT As New DataTable
    Dim bsource As New BindingSource

    Dim SQLString As String = "Select * From table where name like '%" & TxtTransAct.Text & "%' and transactiondate BETWEEN '" & DTPTransAct.Text & "' AND '" & DTPTransAct.Text & "' Limit 5000;"

        DLCmd = New MySqlCommand(SQLString, DLConn)
        DLDA.SelectCommand = DLCmd
        bsource.DataSource = DLDT
        DGVTransAct.DataSource = bsource
    Catch ex As Exception
        Exception = "ExecQuery Error: " & vbNewLine & ex.Message
        Dim RecordCount1 As String = DLDT.Select().Length
        TextBox16.Text = (RecordCount1.ToString() + " Record(s) Found!")
    End Try
End Sub
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300494 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO