@{varmydate="";vardb=Database.Open("test");varsql="select * from udrzba";if(IsPost){mydate=Request.Form["datepicker"];sql="select * from udrzba where datum=@0";}varmydate1=mydate.Substring(6,4)+mydate.Substring(0,2)+mydate.Substring(3,2);vardata=db.Query(sql,mydate1);vargrid=newWebGrid(data,rowsPerPage:20);}<!doctypehtml><htmllang="en"><head><metacharset="utf-8"/><title>jQuery UI Datepicker - Default functionality</title><linkrel="stylesheet"href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"/><scriptsrc="http://code.jquery.com/jquery-1.8.3.js"></script><scriptsrc="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script><linkrel="stylesheet"href="/resources/demos/style.css"/><script>
$(function(){
$("#datepicker").datepicker({
dateFormat:'mm/dd/yy',
onSelect:function(dateText, inst){
$("#datepicker").val(date);}});})</script></head><body><div><formmethod="post"><p>Date: <inputtype="datetime"id="datepicker"name="datepicker"/><inputtype="submit"value="submit"/></p></form></div><div><p>This is my date: @mydate</p></div><div>@grid.GetHtml(tableStyle:"grid",headerStyle:"head",alternatingRowStyle:"alt",columns:grid.Columns(grid.Column("Stroj"),grid.Column("Casti_stroja"),grid.Column("Ukazovatele"),grid.Column("Status"),grid.Column("Poznamky"),grid.Column("Datum")))</div></body></html>
If you change your first row as var mydate = "01/01/1900"; probably the code works.
In any case, my solution isn't without problems: for example, you must test the date to verify if the user has modified it in a way that is not compatible with the original format.
If there is still error. You can just use 3 input fields text type and name them as date month year validate them for the correct data.
Than for the server side just join them as you want. Also if you are getting error doing this. Than you can try to change the table type from datetime to nvarchar to get the time. Thats pretty handy!
Please "Marks As Answer" if any answer helped you out!
~~! FIREWALL !~~
triskac
Member
15 Points
52 Posts
Re: How to add value from popup calendar to variable?
Nov 30, 2012 10:28 AM|LINK
yes here is entire code
GmGregori
Contributor
5564 Points
749 Posts
Re: How to add value from popup calendar to variable?
Nov 30, 2012 10:46 AM|LINK
The error arises from the empty mydate string.
If you change your first row as var mydate = "01/01/1900"; probably the code works.
In any case, my solution isn't without problems: for example, you must test the date to verify if the user has modified it in a way that is not compatible with the original format.
GmGregori
Contributor
5564 Points
749 Posts
Re: How to add value from popup calendar to variable?
Nov 30, 2012 11:25 AM|LINK
I amend my former post. The right function is
You could convert the string from the datepicker to date with the following function too:
In any case you should validate the date if the user can modify the datepicker output.
triskac
Member
15 Points
52 Posts
Re: How to add value from popup calendar to variable?
Nov 30, 2012 07:54 PM|LINK
Gregori thank you very much
this is not working
Afzaal.Ahmad...
Contributor
2759 Points
1060 Posts
Re: How to add value from popup calendar to variable?
Dec 01, 2012 10:11 AM|LINK
If there is still error. You can just use 3 input fields text type and name them as date month year validate them for the correct data.
Than for the server side just join them as you want. Also if you are getting error doing this. Than you can try to change the table type from datetime to nvarchar to get the time. Thats pretty handy!
~~! FIREWALL !~~