0

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.

3
Contributors
3
Replies
14
Views
6 Years
Discussion Span
Last Post by cirno
0

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)

Edited by __avd: Added [code] tags.

0

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.

Edited by cirno: n/a

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.