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,..

var dt = new Date();
       var a = new Date(dt).toLocaleString();

I used above code 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 ..?
12045649 19-Oct-15 3:03am
<html xmlns="">
<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(':');
<body >
<form id="form1" runat="server">


<%--<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 />


.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);
int i= cmd.ExecuteNonQuery();

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

protected void btnsubmit_Click(object sender, EventArgs e)


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:


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