get time value

i have 2 textbox and a submit button which are txttimefrom, txttimeto..the purpose of these 2 textboxes are to let users key in the time...so, when i click the "submit" button, it will show the total time....

e.g time from = 1420
time to = 1600
so, the total time would be 0140 hours.
can anyone help me for this? thank you
0
haur18
1/31/2005 6:26:13 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

10 Replies
557 Views

Similar Articles

[PageSpeed] 11

Hi,

Use something like this:

C#:
DateTime dtFrom = DateTime.ParseExact(txtFrom.Text, "HHmm", CultureInfo.InvariantCulture);
DateTime dtTo = DateTime.ParseExact(txtTo.Text, "HHmm", CultureInfo.InvariantCulture);
TimeSpan ts = dtTo - dtFrom;
txtResult.Text = String.Format("{0:00}{1:00}", ts.Hours, ts.Minutes);
VB:
Dim dtFrom As DateTime = DateTime.ParseExact(txtFrom.Text, "HHmm", CultureInfo.InvariantCulture)
Dim dtTo As DateTime = DateTime.ParseExact(txtTo.Text, "HHmm", CultureInfo.InvariantCulture)
Dim ts As TimeSpan = CType((dtTo - dtFrom), TimeSpan)
Dim txtResult.Text As String = String.Format("{0:00}{1:00}", ts.Hours, ts.Minutes)

Leon Langleyben

MCSD, ASP.NET MVP

Blog
0
llangleyben
1/31/2005 8:33:52 AM
Hi llangleyben!!!

is that code calculate the time for one day that how many hourds has been acheived or it counts through days? I mean is that code to calculate a time that employee works per day or this code is designed for a other specific purpose ? please advice!!

Fadil Alnassar
www.fadilalnassar.com | FREE Nodil Tab Control
http://www.mefranchising.com
0
fadil1977
1/31/2005 9:08:52 AM
i can't compile...how to declare the CultureInfo?
0
haur18
1/31/2005 9:12:55 AM
Just add Imports (using for c#) System.Globalization.

Fadil, this code calculating difference between two dates/times. You can retrieve from resulting TimeSpan object difference in days, hours, minutes etc. as you like.

Leon Langleyben

MCSD, ASP.NET MVP

Blog
0
llangleyben
1/31/2005 2:13:12 PM
oh ... but i'm using vb .net...which system should i import?
0
haur18
2/1/2005 7:28:13 AM
Hi,

It is the same namespace for C# and VB.NET:

Imports System.Globalization

Leon Langleyben

MCSD, ASP.NET MVP

Blog
0
llangleyben
2/1/2005 4:57:31 PM
Hi llangleyben !!!

I just tried to test the code that you wrote. I have problem on Time span
It says '-' operation is not defined. Can you please help?
Thanks
Fadil Alnassar
www.fadilalnassar.com | FREE Nodil Tab Control
http://www.mefranchising.com
0
fadil1977
2/7/2005 9:13:35 AM
Hi Fadil,

In my sample - is operator of DateTime structure. It is defenitely defined. Can you post your code?
Leon Langleyben

MCSD, ASP.NET MVP

Blog
0
llangleyben
2/7/2005 3:44:52 PM
Hi llangleyben!!

Thanks for your reply!!
I actually wrote the same provided code but i posted again just in case. I imported the following

Imports System.Globalization

Now the code is :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dtFrom As DateTime = DateTime.ParseExact(txtfrom.Text, "HHmm", CultureInfo.InvariantCulture)
Dim dtTo As DateTime = DateTime.ParseExact(txtto.Text, "HHmm", CultureInfo.InvariantCulture)
Dim ts As TimeSpan = CType((dtTo - dtFrom), TimeSpan)
Dim txtResult.Text As String = String.Format("{0:00}{1:00}", ts.Hours, ts.Minutes)

End Sub

I hope you ca nhelp!! Thanks again

Fadil Alnassar
www.fadilalnassar.com | FREE Nodil Tab Control
http://www.mefranchising.com
0
fadil1977
2/8/2005 8:48:55 AM
Hi Fadil,

This should work (even in VB :) ):

Dim ts As TimeSpan = New TimeSpan(dtTo.Ticks - dtFrom.Ticks)

Leon Langleyben

MCSD, ASP.NET MVP

Blog
0
llangleyben
2/20/2005 3:13:17 PM
Reply:

Similar Artilces:

getting values from a web form to windows form
Hot Requirement ..... Is there any possible of getting values from a web form to windows form ????? Yes One way i to use the WebRequest and WebResponse classes of the System.Net namespace. For example:  WebRequest request = WebRequest.Create("URL of the web page); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string content = reader.ReadLine(); ....    Reza Nassabehwww.professionalcsharp.comDon't forget to click "Mark as Answer" on the post that helped you. That way fut...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

Get listbox value from the other web form
 Dear all, I want to get the lisbox selecteditem value to a textbox in one web form from the other web page. Should I use session to get this value?Can any one help in this regard? Thanks a lot in advance.  People Develop People Yes you can use Session to get the informations between cross pages.. see below for your referenceTO STORE THE INFO in Session Session["key"] = ListBox1.SelectedItem.Value; Response.Redirect("Page2.aspx");TO GET THE VALUES FROM Sessionprotected void Page_Load(object sender, EventArgs e){    if (Sessio...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

passing values to .net web form application
Hi Can any explain me abt how to pass values to my .NET web form application (designed using PB 11.1) from other web application? My intension is to redirect from a web application (ASP.NET to .net web form application) to my web application with user information. Thanks & Regards, Anbazhagan From the "Deploying Applications and Components to .NET" manual: >>> Starting an application with command line parameters If your application requires command line parameters, you can assign values to the PBCommandParm global property before you deploy the...

Getting values from a vbscript msgbox to use in web form
Hello, Currently I'm calling a vbscript function to pop up a modal dialog box where a user would enter some comments. These comments are passed back to the vbscript funciton fine. Right now i have the "comments" storing in an asp:textbox. I would like to hide these comments on the page, but use the comments in the code behind to store in a database. I tried to just make the visibility on the textbox as false. but then in the codebehind the textbox.value is still null. Is there a way to store that information without showing it on the web form? when the asp:textbox is ...

Request.Form does not get form values
Hi guys, I am new in ASP.NET 2.0 I am stuck with request.form problem I have simple asp:textbox and asp:button nested in the form with runat=server property, but when I want to get textbox value and response.write to page it gets empty, please look at code what do I do wrong?         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>        <asp:Button ID="Button1" runat="server" Text="Button" />------------------------------------------------------------------------------------------...

Send e-mail with web form values (vb.net)
I'm sure this is very simple but;I have a form with numerous (<50) textbox controls and related Label controls; ie: <asp:Label ID="Label1" runat="server" Text="Last Name: "></asp:Label> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>When the form is submitted I want to loop through each label control and textbox control and get their Text values for the e-mail without specifying each control. Anyone have suggestions on the best way to do this?Any assistance appreciated greatly!   Here is a solution for you in VB.net:http://www.extremeexperts.com/...

getting start with vb.net and crystal repots(web form)
I use Crystal Report9 in Visual Studio.NET 2003..... Example at Northwind database I want a application that.....a form include a combobox that contain CustomerID.....If I choose one CustomerID and click OK button....a Report will display information about this Customer......I think that must use Paramater.....how to do that ???? (How do I start to coding --please step by step or sample) please help me !!! Thank you so much!!! very good I have Dropdownlist when I choose the 'month'--> the all data of this field will show I use this Private Sub ddlMonth_Sel...

Webapplication getting values from Child webform to Parent web form ?
I am having two web pages . Parent.aspx and child.aspx . When i click a button in parent.aspx , child.aspx opens , After that i fill some values in Child.aspx . When i click close in Child.aspx ,  I should select all the values that is selected in child.aspx and i should show it in Parent.aspx . How to do it ? Well at the end of the day you have a lot of options. It really comes down to what you are wanting to transfer. Are you familiar with query's? example.aspx?Task=Retrieve;"If Your Question Has Been Answered, Please Mark It As the Answer" raghu_grdr: I am ha...

Changed values not getting passed to UPDATE SQL function on web form
So I have a form that has been giving me fits... It's a form to edit a database entry; on Page_Load, data from the entry loads on the page in various fields (textboxes, drop-down lists, radio button lists, etc). The idea is that the user should be able to upate that data as needed, then hit a "save" button, and an UPDATE query saves the new data to the database. What's happening instead, however, is that the old unchanged data is being passed to the UPDATE query, rather than the new data. Except in one wierd case, when a record is created with only the bare minimum of inf...

VB .net Web Form will not get contents of Text Box
I have created a web form with text boxes that are bound to a DataSet/DataView.  I have created button to navigate up and down the recordset.  That all works fine. I need to have the ability to edit/add text in any of the boxes and then when clicking "Save" button, it would build an UPDATE query to send to the database. When the Save button is clicked, I have coded to DIM a string var (strSQL) to use to build the SQL command.  For some reason, it will only get the text from a text box if the data was pulled the database.  If I add/edit data, then the SQL command will ha...

IN VS.Net how can i get a web form to scroll (design mode)
In design mode in VS.Net, there is a scroll bar next to the web form, but it is grayed out.  I can not figure out how to enable it.  I want to design a web form that is larger in size than the surface area shown in teh deisgn window.  Can someone help out with this?Thank you. VS design surface shows how the page is going to be rendered in the browser. Therefore, there is no 'virtual' large size. In the browser scroll bar appears if the browser window is smaller than the page content. You can make scroll bar to appear by enclosing page content in a large container e...

Web Forms: Get the cells' values from DataGrid with AutoGenerateColumns = true
Dear frinds I've a DataGrid configured with AutoGenerateColumns = True. I've a ItemDataBound event, I want to get the cells' values but all the cells returns a Null String "". The DataGrid contains 14 columns and the fields and all the data are bind correctly, but I want to put the cells' values in variables. For example'I declare these 2 global variables:'Dim sColuna1, sColuna2 As StringPrivate Sub dgAutoGenerate_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgAutoGenerate.ItemDataBound     &nbs...

Web resources about - get time value - asp.net.web-forms

White House undergoes holiday lockdown after man jumps fence
ABC15 Arizona White House undergoes holiday lockdown after man jumps fence ABC15 Arizona Another day, another White House fence jumper. The ...

Serge Kovaleski, ‘New York Times’ Reporter With Arthrogryposis: ‘Donald And I Were On A First-Name Basis ...
Serge Kovaleski, the New York Times reporter who stated that he could not remember “anyone saying there were thousands, or even hundreds, of ...

Unbelievable Lie of the Day: Turkey Says It Had Not Recognized the Aircraft as Russian When it Shot it ...
In the wake of conflicting flight path information with Russian and Turkey differing on the flight path of the Russian aircraft that Turkey downed ...

Mother who left baby in New York City church manger will not face charges
USA TODAY Mother who left baby in New York City church manger will not face charges Jamestown Sun A mother who left her newborn son in a manger ...

Rebel Wilson Wishes Her Fans a Happy Pre-Thanksgiving!
Rebel Wilson is all smiles as she makes her way through Heathrow Airport on Wednesday (November 25) in London, England. The Pitch Perfect 2 ...

LG to build a new OLED plant for more than $8.71 billion
In the past couple of years, we've constantly seen launches of OLED TVs with amazing picture quality, but high prices kept their sales way below ...

Raspberry Pi Zero: computing in smaller size, smaller price
Although development boards, like Beagle Board and Arduino, have been in existence far longer than it, the Raspberry Pi ushered in a revolution ...

France's Hollande, in Moscow, urges grand coalition against Islamic State
By Elizabeth Pineau and Denis Pinchuk MOSCOW (Reuters) - French President Francois Hollande told Russia's Vladimir Putin on Thursday world powers ...

France honors attack victims in city subdued by mourning
PARIS (AP) — A subdued France paid homage Friday to those killed two weeks ago in the attacks that gripped Paris in fear and mourning.

Obama eyes chance to make mark, at last, on climate change
Six years after a fiasco in Copenhagen and a year before he leaves office, a Paris summit offers Barack Obama the chance to make his mark in ...

Resources last updated: 11/27/2015 10:19:33 AM