473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Day duration calculation

Hi, I am a C# beginner, can somebody tells me how to code in the value-changed event of the DateTimePicker control so that it can accept two dates and calculates the difference between them? For example, the duration day between now and any day changed in the daytimepicker?

Thanks in advance
Oct 4 '09 #1
7 3774
whodgson
542 512MB
Google julian day + date.
Its relatively straight forward to write a function to convert a Gregorian date to a Julian date. The period between the two Julian dates and fractions of days constitutes the rquired period to a precision of seconds if needed.
Oct 5 '09 #2
Thanks. But I am thinking of writing this code to see whether it works

Expand|Select|Wrap|Line Numbers
  1. private void dateTimePicker_ValueChanged(object sender, EventArgs e)
  2.         {
  3.  
  4.             int firstMeetingDate = int.Parse(dateTimePicker.Text);
  5.  
  6.             //how can I capture the system current time as an integer?
  7.             //and the requirement said that I should return the int value
  8.             //as day, the format in my daytimePicker is ("week,dd,mm,year)
  9.             //how can I just capture the day and calculate the duration between 
  10.             //them?       
  11.         }
  12.  
Many thanks
Oct 5 '09 #3
GaryTexmo
1,501 Expert 1GB
@Nzsquall
I think...

Expand|Select|Wrap|Line Numbers
  1. DateTime.Now.Ticks
... is what you're looking for.

The DateTime class has lots of stuff to do with time. Here's the MSDN page...
http://msdn.microsoft.com/en-us/libr....datetime.aspx
Oct 5 '09 #4
Plater
7,872 Expert 4TB
A DateTimePicker can only contain a single datetime value at a time, however you can keep track of them.
Use the .Value property of it, rather the the .Text. This will return a DateTime object that you can use to caompare against DateTime.Now
Oct 5 '09 #5
Hi, I have try
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
{
DateTime fistMeetingDate = dateTimePicker.Value;
DateTime currentDate = DateTime.Now;
TimeSpan duration= currentDate - fistMeetingDate;
durationTextBox.Text = duration.ToString();
}
But it appear a very strange String, for instance, today is "Tuesday, 6 October 2009", then I pick firstMeetingDate in the dateTimePicker to "Tuesday, 1 October 2009", the result in the durationTextBox is "5.00:00:57.9269310". How can I get a int day value?
Thanks in advance.
Oct 6 '09 #6
whodgson
542 512MB
Parse the string and extract the first digit/s before the dot
The string format you show is day.hr:m:s.
Oct 6 '09 #7
Plater
7,872 Expert 4TB
Make it say duration.TotalDays.ToString()
That will give you the timespan in terms of whole and fractional days (so 36 hours would give a value of 1.5 days)

Remember to check MSDN on the objects if you are having troubles, its a good resource
Oct 6 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted...
1
by: Dave | last post by:
Greetings, I am trying to create a duration field in a query. I have a field with a start time and a field with an end time. They are both in military time, and are formatted as hours:minutes. I...
2
by: Del | last post by:
Thanks in advance for any help. I have a database that was created in Access 2000. Several users have been upgraded to Access 2003. Since upgrading to 2003 we have noticed that some of the...
4
by: Stephen Young | last post by:
Hello Have a bit of a problem, im trying to get the total number of hours:minutes for all actions over the month in a query, have tried two methods to no luck... Duration This Month:...
4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
15
by: bcpkh | last post by:
Hello All I have a simple task that is driving me crazy. A string representing a duration in the following format is passed to my application, a function is dedicated to convert this duration to...
3
by: Keith Wilby | last post by:
Here's something I thought I'd know how to do ... I have an Appointments table and want to add a duration (integer representing hours) to a start time (Date/Time field, "Short Time" format) to...
1
by: Giacomo Catenazzi | last post by:
Hello, To learn the details of C, I've build the following example, could you check if it is correct and if it miss some important cases? Are there some useful (real cases) examples of: -...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.