Hello again, codegurus.

I need to ask your assistance in converting string to datetype, from 'dd/mm/yyyy' to 'yyyy-mm-dd'.

The user could key in either the 'dd/mm/yyyy' format or 'yyyy-mm-dd' format in a textbox.
the system would check for both format and convert both to the 'yyyy-mm-dd' date format, to be able to save the value in a datetype field in a MySQL table.

I am confused, and testing some codes from google search still doesn't give me a solution.

Thanks in advance.

if u want to retrieve date as string to value then
use this

Dim myDate As DateTime = DateTime.Now
   datetimepicker.Value = DateTime.ParseExact(dr.Item("product_date"), "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None)
Dim dt As Date = "12/13/2010"
        MsgBox(Format(dt, "yyyy-MM-dd"))

I used

txt2.Text = str2date1(txt1.Text)

where

Function str2date1(ByVal strInputText As String) As String

        Dim dt As Date = strInputText
        Return (Format(dt, "yyyy-MM-dd"))

    End Function

Thank you so much for the helpful tips, bhagawatshinde and codeorder.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.