mist4keclan 0 Newbie Poster

How to Update Database Datetime in This Format " dd MMM yyyy HH:mm:ss 'GMT' "With Vb.net Program
I Searched a lot about how to Get The Time online and i found a solution You will found it in my Codes.

My Aim is to make a MemberShip DateTime , First Step to make the program get the Time from internet startdate then add the Time which is the membership time as enddate,Second Step when the program run again it will replace the start time with the actual time "Got from internet too" and substract it with the enddate

Here is My Database Structure (Note i tried to make the enddate and startdate As DateTime but it failed):

Database Structure

Here is my Program :
Program Photo

here is my code :


    Imports System.Globalization
    Imports System.Net
    Imports MySql.Data.MySqlClient

    Public Class Form1
        Dim date1 As DateTime
        Dim date2 As DateTime
        Dim date3 As DateTime
        Dim x As DateTime
        Public Shared Function GetNistTime() As DateTime
            Dim myHttpWebRequest = CType(WebRequest.Create("http://www.microsoft.com"), HttpWebRequest)

            Dim response = myHttpWebRequest.GetResponse()
            Dim todaysDates As String = response.Headers("date")
            Return DateTime.ParseExact(todaysDates, "ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture.DateTimeFormat, DateTimeStyles.AssumeUniversal)
        End Function

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            x = GetNistTime()
            TextBox1.Text = x

            date1 = CStr(x.AddMonths(1))
            Dim MySqlConn = New MySqlConnection
            MySqlConn.ConnectionString = "server=localhost;userid=root;password=123456789;database=test"
            Dim Reader As MySqlDataReader
            Dim Query As String
            Dim sqlcommand As MySqlCommand
            Try
                MySqlConn.Open()
                Query = "UPDATE test.time SET startdate='" & x & "',enddate='" & date1 & "' WHERE username='program'"
                sqlcommand = New MySqlCommand(Query, MySqlConn)
                Reader = sqlcommand.ExecuteReader
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                MySqlConn.Dispose()
            End Try

        End Sub

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim MySqlConn = New MySqlConnection
            MySqlConn.ConnectionString = "server=localhost;userid=root;password=123456789;database=test"
            Dim Reader As MySqlDataReader
            Dim Query As String
            Dim sqlcommand As MySqlCommand
            Try
                MySqlConn.Open()
                Query = "Select * from test.time  WHERE username='program'"
                sqlcommand = New MySqlCommand(Query, MySqlConn)
                Reader = sqlcommand.ExecuteReader
                While Reader.Read
                    date2 = Reader.GetDateTime("startdate")
                    date3 = Reader.GetDateTime("enddate")
                End While
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                MySqlConn.Dispose()
            End Try
            TextBox2.Text = date2
            TextBox3.Text = date3
        End Sub
    End Class

When i Run the Program and Press button2 I got this Error:

Program Error Photo

then when i press ok on ex.message this writen in TextBox2 & TextBox3:

Program Error Photo

This is the out put which stored in the Database:

The Out Put in Database

Please Help Me And Edit anything you Want in code or here, if you have another Idea Let me know it, sorry if i put All the Details and seem boring,thanks

i Know a way to replace "ص" or "م" to "AM" and "PM" If you have Any way to get the Date with "Am" and "PM" directly i would be Grateful