How to convert the datetime into a string for use in the SQL ‘ statement?
<asp:label id=”Label2″ runat=”server”>Select a culture: </asp:label>
<asp:dropdownlist id=”ddlCulture” runat=”server” autopostback=”True”></asp:dropdownlist>
<P></P>
<asp:label id=”Label3″ runat=”server”>DateTime in Selected Culture</asp:label>
<asp:textbox id=”TextBox1″ runat=”server”></asp:textbox>
<p>
<asp:label id=”Label1″ runat=”server”></asp:label>
VB.NET
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘Put user code to initialize the page here
If Not Page.IsPostBack Then
Dim cInfo As CultureInfo
For Each cInfo In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
ddlCulture.Items.Add(cInfo.Name)
Next
End If
End Sub
Private Sub ddlCulture_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlCulture.SelectedIndexChanged
‘ Get a CultureInfo object based on culture selection in dropdownlist
Dim cInfo As CultureInfo = New CultureInfo(ddlCulture.SelectedItem.Text)
‘ Get a CultureInfo object based on Invariant culture
Dim cInfoNeutral As CultureInfo = New CultureInfo(“”)
‘ Display the datetime based on the formatting of the selected culture
TextBox1.Text = Convert.ToString(Now, cInfo.DateTimeFormat)
‘ Create a DateTime variable to hold the Invariant time
Dim dt As DateTime
dt = Convert.ToDateTime(TextBox1.Text, cInfo.DateTimeFormat)
‘Convert the datetime into a string for use in the SQL statement
Label1.Text = “… WHERE ([Date] < ‘” & _
Convert.ToString(dt, cInfoNeutral.DateTimeFormat) & “‘)”
End Sub
Read more on How to convert the datetime into a string for use in the SQL ‘ statement?…
