Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2036
  • Last Modified:

Date and Time formats problem(timezones)

Hello!


Im creating a form that lets users enter some information and now i want date stored in this format to a textbox 10/13/2007 currently now it makes it 2007-10-13

One more thing
I want the time to be shown in CEST Central european format (swedish stockholm) format)

Anyone know if its possible?

My code in the add page

<code>

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Untitled Page" %>


<%@ Register Assembly="System.Web.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language="javascript" type="text/javascript">
// <!CDATA[

function Image2_onclick() {

}

function IMG1_onclick() {

}

// ]]>
</script>

    &nbsp;
           <asp:Label ID="Label1" runat="server" Font-Bold="True" Style="z-index: 100; left: 3px;
                position: absolute; top: 90px" Text="Ban From:"></asp:Label>
            <asp:RadioButtonList ID="radiolist" runat="server" Height="129px" Style="z-index: 101;
                left: 32px; position: absolute; top: 110px" Font-Italic="False">
                <asp:ListItem>SA:MP</asp:ListItem>
                <asp:ListItem Value="MTA:VC">MTA:VC</asp:ListItem>
                <asp:ListItem>Teamspeak</asp:ListItem>
                <asp:ListItem>Forum</asp:ListItem>
            </asp:RadioButtonList>
            <asp:CheckBoxList ID="Reasons" runat="server" Style="z-index: 102; left: 5px; position: absolute;
                top: 380px">
                <asp:ListItem Text="Spamming/flooding" Value="1"></asp:ListItem>
                <asp:ListItem Text="Flaming" Value="2"></asp:ListItem>
                <asp:ListItem Text="Constant deathmatching" Value="3"></asp:ListItem>
                <asp:ListItem Text="Teleport hacking" Value="4"></asp:ListItem>
                <asp:ListItem Text="Speed hacking" Value="5"></asp:ListItem>
                <asp:ListItem Text="Weapon hacking" Value="6"></asp:ListItem>
                <asp:ListItem Text="Money cheating" Value="7"></asp:ListItem>
                <asp:ListItem Text="Crashing" Value="8"></asp:ListItem>
                <asp:ListItem Text="Other (Specify in 'Details'field)" Value="9"></asp:ListItem>
            </asp:CheckBoxList>
            <asp:Label ID="Label2" runat="server" Font-Bold="True" Style="z-index: 103; left: 5px;
                position: absolute; top: 364px" Text="Reason:"></asp:Label>
    &nbsp; &nbsp;&nbsp;
            <asp:Label ID="Label3" runat="server" Font-Bold="True" Style="z-index: 104; left: 5px;
                position: absolute; top: 252px" Text="Player nickname:"></asp:Label>
            <asp:TextBox ID="tbPlayerNickname" runat="server" Style="z-index: 105; left: 5px; position: absolute;
                top: 272px"></asp:TextBox>
            <asp:Label ID="Label4" runat="server" Font-Bold="True" Height="1px" Style="z-index: 106;
                left: 5px; position: absolute; top: 296px" Text="IP address:" Width="101px"></asp:Label>
            <asp:TextBox ID="tbIP" runat="server" Style="z-index: 107; left: 5px; position: absolute;
                top: 315px"></asp:TextBox>
            <asp:CheckBox ID="CheckBox1" runat="server" Style="z-index: 108; left: 8px; position: absolute;
                top: 339px" Text="Dynamic IP" />
    &nbsp;
            <asp:Label ID="Label6" runat="server" Font-Bold="True" Style="z-index: 109; left: 5px;
                position: absolute; top: 686px" Text="Date:"></asp:Label>
            <asp:TextBox ID="tbDATE" runat="server" Style="z-index: 110; left: 6px; position: absolute;
                top: 705px"></asp:TextBox>
            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Calendar_scheduleHS.png"
                Style="z-index: 111; left: 153px; position: absolute; top: 710px" />
    <ajaxToolkit:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="tbDATE" PopupButtonID="ImageButton1">
    </ajaxToolkit:CalendarExtender>
    &nbsp;
    <asp:Label ID="Label8" runat="server" Style="z-index: 113; left: 44px; position: absolute;
        top: 641px" Text="(CET Server Time / GMT +1)"></asp:Label>
    &nbsp;
            &nbsp;&nbsp;
    <asp:Label ID="Label7" runat="server" Font-Bold="True" Height="12px" Style="z-index: 114;
        left: 3px; position: absolute; top: 932px" Text="Banned By"></asp:Label>
    <input id="Reset1" style="z-index: 120; left: 52px; position: absolute; top: 953px"
        type="reset" value="reset" />
            <br />
            <hr style="z-index: 114; left: 0px; position: absolute; top: 0px" />
            &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
            <br />
            <hr style="z-index: 113; left: 0px; position: absolute; top: 0px" />
            <asp:LoginName ID="LoginName1" runat="server" Style="z-index: 115; left: 80px; position: absolute;
                top: 932px" />
            <hr style="z-index: 115; left: 0px; position: absolute; top: 0px" />
    &nbsp;&nbsp;
    <img src="banfor/Teamspeak.jpg" style="z-index: 116; left: 3px; width: 28px; position: absolute;
        top: 176px; height: 28px" />
    <img id="IMG1" src="banfor/SAMP.jpg" style="z-index: 117; left: 3px; width: 28px;
        position: absolute; top: 110px; height: 28px" onclick="return IMG1_onclick()" />
    <img src="banfor/MTAVC.jpg" style="z-index: 118; left: 3px; width: 28px; position: absolute;
        top: 143px; height: 28px" />
    <img src="banfor/Forum1.jpg" style="z-index: 119; left: 3px; position: absolute;
        top: 210px" />
            <br />
           
               <asp:Button ID="btnDoInsert" runat="server" Text="Add" style="z-index: 116; left: 2px; position: absolute; top: 953px" />
            <asp:Label ID="labelDetails" runat="server" Font-Bold="True" Style="z-index: 117;
                left: 5px; position: absolute; top: 599px" Text="Details:"></asp:Label>
            <asp:TextBox ID="tbDetails" runat="server" Style="z-index: 118; left: 5px; position: absolute;
                top: 618px"></asp:TextBox>
    &nbsp;
    <asp:Label ID="Label5" runat="server" Font-Bold="True" Height="19px" Style="z-index: 120;
        left: 5px; position: absolute; top: 639px" Text="Time:"></asp:Label>
    <asp:Label ID="Label9" runat="server" ForeColor="#FF0000" Height="11px" Style="z-index: 121;
        left: 114px; position: absolute; top: 952px" Width="155px"></asp:Label>
   
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
<asp:TextBox style="Z-INDEX: 102; LEFT: 6px; POSITION: absolute; TOP: 662px" id="txtTime" runat="server" OnTextChanged="txtTime_TextChanged1"></asp:TextBox> <asp:CheckBox style="Z-INDEX: 100; LEFT: 153px; POSITION: absolute; TOP: 661px" id="CheckBox2" runat="server" Text="Time now" Height="19px" Width="110px" Checked="True"></asp:CheckBox>
</ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

</code>

Vb code
<code>
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub btnDoInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDoInsert.Click
        Dim DynIP As String
        If CheckBox1.Checked Then
            DynIP = "Yes"
        Else
            DynIP = "No"

        End If
        Dim usrname As String
        usrname = User.Identity.Name

        Dim li As System.Web.UI.WebControls.ListItem
        li = radiolist.SelectedItem

        Dim selectedBanfor As String

        selectedBanfor = li.Text


        Dim selectedReason As String = String.Empty

        Dim IsSelectionsMade As Boolean = False

        For Each tmpListItem As ListItem In Reasons.Items
            If (tmpListItem.Selected) Then
                selectedReason += tmpListItem.Text + ", "
                IsSelectionsMade = True
            End If
        Next

        If (IsSelectionsMade) Then
            selectedReason = selectedReason.Substring(0, selectedReason.Length - 2)

            DoInsert(selectedBanfor, tbPlayerNickname.Text, tbIP.Text, DynIP, selectedReason, tbDATE.Text, txtTime.Text, tbDetails.Text, usrname, False)
        Else

        End If

    End Sub
    Private Sub DoInsert(ByVal BanFor As String, ByVal PlayerNickName As String, ByVal IPAddress As String, ByVal DynIP As String, ByVal Reasons As String, ByVal tbDATE As String, ByVal Time As String, ByVal Details As String, ByVal BannedBy As String, ByVal CaseClosed As Boolean)

        'ConnectionString till databasen, ändra sökvägen så att den blir rätt
        Dim ConnectionString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" + Server.MapPath("~/App_Data/Database.mdf") + ";Integrated Security=True;User Instance=True"

        'Skapa en ny SQL-connection med rätt ConnectionSring
        Dim CurrentSQLConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConnectionString)

        'Skapa kommando-texten som sätter in en rad i tabellen
        Dim SQLCommand As String = "INSERT INTO Argobanlist (BanFor, PlayerNickName, IPAddress, DynamicIP, Reasons, Date, Time , Details, BannedBy, CaseClosed) "

        SQLCommand += " VALUES ('" + BanFor + "', "
        SQLCommand += "'" + PlayerNickName + "', "
        SQLCommand += "'" + IPAddress + "', "
        SQLCommand += "'" + DynIP + "', "
        SQLCommand += "'" + Reasons + "', "
        SQLCommand += "'" + tbDATE + "', "
        SQLCommand += "'" + Time + "', "
        SQLCommand += "'" + Details + "', "
        SQLCommand += "'" + BannedBy + "', "
        SQLCommand += "" + System.Convert.ToInt32(CaseClosed).ToString() + ")"

        'Öppna anslutning till databasen
        CurrentSQLConnection.Open()

        'Skapa nytt SQL-kommando
        Dim sqlCmd_InsertBan As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(SQLCommand, CurrentSQLConnection)

        'Utför kommando
        sqlCmd_InsertBan.ExecuteNonQuery()
        Label9.Text = "Ban added"

        'Stäng anslutningen till databasen igen
        CurrentSQLConnection.Close()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If CheckBox2.Checked = False Then
            txtTime.Enabled = True
        End If
        If CheckBox2.Checked = True Then
            txtTime.Enabled = False
            Dim timenow As String
            timenow = DateTime.Now.ToLongTimeString
            txtTime.Text = timenow
        End If
        Dim dtNow As DateTime = DateTime.Now
        tbDATE.Text = dtNow.Date

    End Sub
</code>


Hope anyway can help me

If anyone knows about it i would be glad if you can give me the answer in VB code not on C#


Regards
Clooak
0
clooak
Asked:
clooak
  • 4
  • 2
1 Solution
 
GawaiCommented:
Dim d As New Date
d = d.Now
Response.Write("<BR>" & Format(d, "MMM/dd/yyyy"))

0
 
GawaiCommented:
sori this one is correct
Response.Write("<BR>" & Format(d, "MM/dd/yyyy"))
0
 
GawaiCommented:
for timezone you need to use AddHours(+/- time diff)
here is the result online. http://www.sahilonline.org/time2.aspx

<%
Response.Write("<BR>Server Date & Time : " & DateTime.Now)
Response.Write("<BR>Server Date & Time + 2 hrs: " & DateTime.Now.AddHours(2))
%>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
clooakAuthor Commented:
Still i dont get how i change the date format into a variable etc

Dim dtNow As DateTime = DateTime.Now
tbDATE.Text = dtNow.Date
--
When i execute the above code i will get the date in 2004-03-17

I want it to be in this format
17/03/2007

dd/mm/yyyy

Anyone know how to accomplish that?
0
 
GawaiCommented:
Dim d As New Date
d = d.Now
Response.Write("<BR>" & Format(d, "dd/MM/yyyy"))

it returns dd/mm/yyyy

your question was formating date as : mm/dd/yyy

>>Im creating a form that lets users enter some information and now i want date stored in this format to a textbox 10/13/2007 currently now it makes it 2007-10-13



0
 
clooakAuthor Commented:
Problem solved by myself

My problem was that i didnt set the Culturel setting to US

I did that then it worked like a charm!

Thanks anyway for all help
0
 
Computer101Commented:
PAQed with points refunded (75)

Computer101
EE Admin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now