VB.NET - Change the Date Format at Runtime - Asked By Jem Savery on 30-Oct-08 05:56 AM

Hi Friends,

I have a date in dd/mm/yyyy format.

The value for the date is "20/02/2003"

Now when I am checking the date using IsDate function, it give me FALSE value as the date is in format dd/mm/yyyy.

So, should I have to change the format first to "mm/dd/yyyy" and if so how can it be done using vb.net code?

Then I will be getting the value like "02/20/2003".

Please its urgent.

Change the Date Format at Runtime - Binny ch replied to Jem Savery on 30-Oct-08 06:11 AM

This code is very simple and very use full if u want to change system dateformat in runtime.
Imports Microsoft.Win32

 Dim reg As RegistryKey
reg = Registry.Users.OpenSubKey("S-1-5-21-1757981266-861567501-682003330-500\Control Panel\International", True)
If Convert.ToString(reg).Trim = String.Empty Then
MsgBox("Blank")
Else
reg.SetValue("sShortDate", "dd/MM/yyyy")
reg.SetValue("sLongDate", "dd/MM/yyyy")
End If

Change the Date Format at Runtime - Asked By Jem Savery on 30-Oct-08 06:22 AM

You guys are not getting, I don't have to convert datetime to specific format.

I am having a string with value "20/02/2003", When even I am going to convert it to DateTime, it gives an error.

So, I want to convert this string to "02/20/2003". And this is not a single value, I have a column such format with more than
2000 rows.

Please help.

simply use this format - Web Star replied to Jem Savery on 30-Oct-08 08:34 AM

yourDate.ToString("MM-dd-yyyy");

or Format(yourDate, "dd/mm/yyyy")

Change the Date Format at Runtime - Shailendrasinh Parmar replied to Jem Savery on 01-Nov-08 04:01 AM

See the following function to change the date format

Private Function ChangeDateFormat(ByVal JoinDate As Object) As Object
        Dim dateString, format As String
        Dim result As Date
        Dim provider As IFormatProvider = New System.Globalization.CultureInfo("en-CA", True)

        If Not IsDBNull(JoinDate) Then
                dateString = JoinDate.ToString
                result = DateTime.Parse(dateString, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault)
                Return result
        Else
                Return Nothing
        End If

End Function

And call that function like this

Dim Join_Date As Object = ChangeDateFormat(SourceRow.Item("JoinDate"))

Hope it helps.

Saad replied to Jem Savery on 15-Feb-11 03:00 PM
complete resource of string.format function in vb.net is available at the below mentioned link:
http://bitsbyta.blogspot.com/2010/12/string.html
Saad replied to Saad on 15-Feb-11 03:02 PM
Click here to get information about String.Format function in vb.net
complete resource of string.format function in vb.net is available at the below mentioned link: http://bitsbyta.blogspot.com/2010/12/string.html
Saad replied to Saad on 15-Feb-11 03:05 PM
Click here to get information about String.Format function in vb.net
http://bitsbyta.blogspot.com/2010/12/string.html
Saad replied to Saad on 15-Feb-11 03:07 PM
Click here to get information about String.Format function in vb.net
http://bitsbyta.blogspot.com/2010/12/string.html