Click here to Skip to main content
15,036,441 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello friends,..

C#
var dt = new Date();
       var a = new Date(dt).toLocaleString();
       alert(a);


I used above code ...here i wanted the var variable to int variable because i wanted to send it to database(which is in datetime format)..Can anybody help me ..?
Posted
Comments
12045649 19-Oct-15 3:03am
   
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function getdates() {
var today = new Date()

document.getElementById('Label1').innerHTML = [today.getDate(), today.getMonth() + 1, today.getFullYear()].join('/') + ' ' + [today.getHours(), today.getMinutes(), today.getSeconds()].join(':');
}
</script>
</head>
<body >
<form id="form1" runat="server">

<div>

<%--<label id="lbldateformat" />--%>
<asp:Label ID="Label1" runat="server" Text="Label">
<br />
<asp:Label ID="Label2" runat="server" Text="Label">
<br />
<asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClick="btnsubmit_Click" />
<br />

</div>
</form>
</body>
</html>

.cs code


public partial class dateformat : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("server=ADMIN-PC\\SQLEXPRESS;database=rama;integrated security=true");

protected void Page_Load(object sender, EventArgs e)
{
Label2.Text = Label1.Text;
}
public void times()
{
string x = Label1.Text;
SqlCommand cmd = new SqlCommand("insert into times values(@x)", conn);
cmd.Parameters.AddWithValue("@x", x);
conn.Open();
int i= cmd.ExecuteNonQuery();
conn.Close();

if (i == 1)
{
Label2.Text = "Inserted";
}
else
{
Label2.Text = "Not Inserted";
}
}

protected void btnsubmit_Click(object sender, EventArgs e)
{
times();
}




}

I have used the following code ..It is not inserting into database..Can any one help me please..

1 solution

Here is the script to get time stamp client side:

JavaScript
alert(Date.now());
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900