Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
See the code which get datetime using jquery plugin

XML
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test1.aspx.vb" Inherits="gfln1.test1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/ui.all.css" rel="stylesheet" type="text/css" />
 <script src="http://projectcodegen.com/jquery.ui.datetimepicker.js" type="text/javascript"></script>
  </head>
  <script type="text/javascript">
  $(function() {
  $('#TextBox1').datetimepicker();
  $('#TextBox2').datetimepicker();

  });
  </script>

<body>
    <form id="form1" runat="server">
    <div>

        Enter Start Date/Time<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        Enter End Date/Time<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        Enter Conference days<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
         <br />
          <asp:Button ID="Button1" runat="server" Text="Calculate Hours For businees" />

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


Now i need to get time from datetime and get hours, How to do this, I have few lines of code but unable to get duration from both time (mind it just not date).

VB
Dim s1, s2 As DateTime
       s1 = DateTime.Parse(Me.TextBox1.Text)
       s2 = DateTime.Parse(Me.TextBox2.Text)
Posted
Updated 23-Dec-10 17:22pm
v3
Comments
Ankur\m/ 24-Dec-10 4:29am    
I have deleted your answer for a simple reason that it was not an answer. If you need to add more details to you question, click 'Improve Answer' below the question, add/modify the question and update it.
If you need some clarification against a user's answer, use 'Add Comment' feature below the answer. This also notifies the user about your comment so that he/she can respond back.
And finally, if an answer helps you solve your issue, vote it high and select "Accept Answer" against it.

You convert the text of the textbox to datetime.
Then you can retrieve the required details from it.
This is how you get hour and time from it.

VB
Protected Sub Button1_Click(sender As Object, e As EventArgs)
	Dim dt As DateTime = Convert.ToDateTime(TextBox1.Text) 'suppose {12/24/2010 10:10:00 AM}
	Dim hours As Integer = dt.Hour '10
	Dim longTimeString As String = dt.ToLongTimeString() '"10:10:00 AM"
	Dim shortTimeString As String = dt.ToShortTimeString() '"10:10 AM"
End Sub


I suggest you to go through the DateTime class on MSDN - here

PS: I wrote the program in C# and converted it to vb using online converters.

Edit: Added output.
 
Share this answer
 
v2
try this
hid_Ticker.Value = TimeSpan.Parse(hid_Ticker.Value).Add(new TimeSpan(0, 0, 1)).ToString();
lit_Timer.Text = hid_Ticker.Value.ToString();
string _s = lit_Timer.Text.ToString();
DateTime _nodetime;
if (DateTime.TryParse(_s,out _nodetime))
{
TimeSpan ts = new TimeSpan(_nodetime.Hour, _nodetime.Minute, _nodetime.Second);
Session.Remove("_nodetime");
collecthours here = ts.TotalDays.ToString();
}
 
Share this answer
 
Comments
Ankur\m/ 23-Dec-10 23:46pm    
What is hid_Ticker and so many other variables used? Did you understand what OP is asking?
Ankur\m/ 24-Dec-10 0:26am    
[moved from answer]
TejuKrishna wrote:
for u r clarification
string _s;
DateTime _nodetime;
if(DateTime.TryParse(_s,out _nodetime))
{
TimeSpan ts=new Timespan(_nodetime.Hour,_nodetime.Minute,_nodetime.Second);
your string varible=ts.TotalDays.ToString();
}
in previous answer u asked so many variable used that's are for showing the time on my form i.e.it literal control and one hidden field control if any doubt pls feel free to ask
Ankur\m/ 24-Dec-10 0:31am    
You need to read the question again. Your answer doesn't answer the question in any way.
TejuKrishna 24-Dec-10 0:37am    
Yes I read it carefully and then only submitting the answer pls try to understand this code is written in timer controls tick event so that i'm able to calculate the incremented time also.
Ankur\m/ 24-Dec-10 0:47am    
OP said he already has datetime picker in place. All he needs is the value of hour and time (from the date string selected in the textbox using the datetime picker) in the code behind when the page post backs. Now tell me how it answers the question?

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