how to inverse the date string in vb.net ??

251 views
Skip to first unread message

Eddy Wu

unread,
Feb 29, 2012, 12:22:49 PM2/29/12
to dotnetde...@googlegroups.com
my project contains one DateTimePicker, one Button and a ListBox. each time the user click the button then the date string value would pass in the ListBox Control, I had declared one User Defined Function named "GetSQLRawFormattedDate(ByVal SDate As String) As String" to handled the reverse order of the character string representation of the Date String from right to left so it would looks like "20120301", I think this formatted datestring can then be pass to the MySql table structure, but unfortunately it ran to did not any changes to the result as I expected before.

please examine the code snippet I had done so far :
............................................
............................................
............................................

// The Trigger Section
 Private Sub BtnParser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnParser.Click
        Dim strdate As String = DateTimePicker1.Value.ToShortDateString
        Dim sqlformstr As String = GetSQLRawFormattedDate(strdate.Trim)

        ListBox1.Items.Add(sqlformstr)

    End Sub

Private Function GetSQLRawFormattedDate(ByVal SDate As String) As String
        Dim tempStr As String = SDate
        Dim retStr As String = Nothing

        For n As Integer = tempStr.Length - 1 To 0
            If (tempStr.Chars(n) <> "/"c) Or (tempStr.Chars(n) <> "-"c) Then
                retStr &= String.Concat("", tempStr(n))
            End If
        Next

        Return tempStr.Trim
    End Function

but still didn't show any positive changes, please help ...

Reuben Bartolo

unread,
Mar 2, 2012, 3:08:08 AM3/2/12
to dotnetde...@googlegroups.com
You can either translate it at an SQL level,  http://whatiseeinit.blogspot.com/2012/02/conversion-of-dates-in-sql.html 


Whatever you do, do not do it manually by altering strings.


--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to dotnetde...@googlegroups.com
To unsubscribe from this group, send email to
dotnetdevelopm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net

Niels

unread,
Mar 1, 2012, 6:22:05 AM3/1/12
to dotnetde...@googlegroups.com
Hello,

For this, you should not use the GetSQLRawFormattedDate function, but the DateTime value of the date time picker (DateTimePicker1.Value)

You can just do:
DateTimePicker1.Value.ToString("yyyyMMdd")

Easy enough!

Niels


--

Cerebrus

unread,
Mar 6, 2012, 1:18:18 AM3/6/12
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Doesn't the MySQL connector handle datetime types automatically ?? Why
the need to convert it to a (reversed) date string ?

Manuel Lazo

unread,
Mar 6, 2012, 10:10:45 AM3/6/12
to dotnetde...@googlegroups.com
hello everyone:

if you want to change to value of the date easy, use FORMAT(datetime.value,"ddMMyyyy") or the format what u like.
or in the moment when you variable get the value do this:


private ValueOfDate  as Datetime

    Public Property ValueOfDate() As DateTime
        Get
            Return _ValueOfDate
        End Get
        Set(ByVal value As DateTime)
            _ ValueOfDate  = format(value,"ddMMyyyyy")
        End Set
    End Property

but remember what type is your field of mysql table?
if is Datetime = the format default is yyyy-MM-dd then you have to format the value and this is all :).


Manuel Lazo.

Lima - Perú.

2012/3/6 Cerebrus <zor...@sify.com>
Doesn't the MySQL connector handle datetime types automatically ?? Why
the need to convert it to a (reversed) date string ?
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to dotnetde...@googlegroups.com
To unsubscribe from this group, send email to
dotnetdevelopm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net



--
Manuel Lazo.

vishal sharma

unread,
Mar 6, 2012, 10:38:12 AM3/6/12
to dotnetde...@googlegroups.com
On Tue, Mar 6, 2012 at 11:48 AM, Cerebrus <zor...@sify.com> wrote:
Doesn't the MySQL connector handle datetime types automatically ?? Why
the need to convert it to a (reversed) date string ?
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to dotnetde...@googlegroups.com
To unsubscribe from this group, send email to
dotnetdevelopm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net


you have to use String.Format and then specify 0:D like arguments hope it helps

or why you want to reverse just tell user in which manner you enter a date...

you can use maskededitExtender in ajax control toolkit to do that..

hope it helps..
Reply all
Reply to author
Forward
0 new messages