i am looking to convert a date in string in javascript/jquery like '20/11/2013' to datetime for code behind like 2013-11-20 00:00:00.000 to be passed to the SQL.I cant add any extra jquery plugin to achieve this.
-
do you really need to convert it clientside with javascript? Could you pass it to your C# and convert it there?MakingItUp– MakingItUp2013-11-13 11:46:42 +00:00Commented Nov 13, 2013 at 11:46
-
You haven't to invent a bicycle ;) (w3schools.com/jsref/jsref_obj_date.asp)user2604650– user26046502013-11-13 11:48:16 +00:00Commented Nov 13, 2013 at 11:48
-
possible duplicate of Formatting a date in JavaScriptFrank van Puffelen– Frank van Puffelen2013-11-13 12:37:24 +00:00Commented Nov 13, 2013 at 12:37
Add a comment
|
6 Answers
Hi you can use with this.
new Date('2013-04-13');
or
new Date('2013-04-13T11:51:00');
1 Comment
jack
var a = "2013-11-20T00:00:00.000"; alert(new Date(a));
To get value from javascript you can use hidden field.
<script type="text/javascript">
function abc()
{
var str="datetime value";
document.getElementById("Hidden1").value=str;
}
</script>
<body>
<form id="form1" runat="server">
<div>
<input id="Hidden1" type="hidden" runat="server" />
<asp:Button ID="Button1" runat="server" OnClientClick="abc()" Text="Button"
onclick="Button1_Click" />
</div>
</form>
</body>
protected void Button1_Click(object sender, EventArgs e)
{
//Get the string
string datetime=Hidden1.Value
//Convert to datetime
//TODO
}