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
7 3774
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.
Thanks. But I am thinking of writing this code to see whether it works -
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
-
{
-
-
int firstMeetingDate = int.Parse(dateTimePicker.Text);
-
-
//how can I capture the system current time as an integer?
-
//and the requirement said that I should return the int value
-
//as day, the format in my daytimePicker is ("week,dd,mm,year)
-
//how can I just capture the day and calculate the duration between
-
//them?
-
}
-
Many thanks
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
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.
Parse the string and extract the first digit/s before the dot
The string format you show is day.hr:m:s.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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...
|
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:
-...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |