String to DateTime and DateTime to String

This is totally a VB.Net

If you want to convert the specified string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information, you can try below

String to DateTime

// String to DateTime
String MyString;
MyString = “1999-09-01 21:34 PM”;
//MyString = “1999-09-01 21:34 p.m.”; //Depends on your regional settings

DateTime MyDateTime;
MyDateTime = new DateTime();
MyDateTime = DateTime.ParseExact(MyString, “yyyy-MM-dd HH:mm tt”,

DateTime to String

//DateTime to String
MyDateTime = new DateTime(1999, 09, 01, 21, 34, 00);
String MyString;
MyString = MyDateTime.ToString(“yyyy-MM-dd HH:mm tt”);


Http POST in VB.Net

This is a simple code in that send Http POST to a webpage and display the response.

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim myWebReq As HttpWebRequest
Dim myWebResp As HttpWebResponse
Dim encoding As New System.Text.ASCIIEncoding()
Dim postData As String
Dim data() As Byte
Dim sr As StreamReader
Dim sw As StreamWriter

postData = “username=b”
postData += “&”
postData += “password=k”
data = encoding.GetBytes(postData)

myWebReq = WebRequest.Create(“http://localhost/authenticate”)
myWebReq.Method = “POST”
myWebReq.ContentType = “application/x-www-form-urlencoded”
myWebReq.ContentLength = data.Length

Dim myStream As Stream = myWebReq.GetRequestStream()
myStream.Write(data, 0, data.Length)
myWebResp = myWebReq.GetResponse
sr = New StreamReader(myWebResp.GetResponseStream)
Dim strHTML As String = sr.ReadToEnd
End Sub
This code is invoked when user submit a button, easy and simple