954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to convert string to datetype, from dd/mm/yyyy to yyyy-mm-dd

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.

cirno
Newbie Poster
12 posts since Nov 2010
Reputation Points: 10
Solved Threads: 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)
bhagawatshinde
Posting Whiz
315 posts since Sep 2010
Reputation Points: 21
Solved Threads: 22
 
Dim dt As Date = "12/13/2010"
        MsgBox(Format(dt, "yyyy-MM-dd"))
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

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.

cirno
Newbie Poster
12 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: