By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,903 Members | 1,973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,903 IT Pros & Developers. It's quick & easy.

DateTime AddMinutes Format Issue

P: n/a
I'd like to have a string assigned the value of a
DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM"
format.

For example:

DateTime.Now.AddMinutes(30) returns "00:30"

DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"

DateTime.Now.AdMinutes(-45)) returns "-00:45"

I've tried all kinds of Format specifiers and nothing is working, any help
is appreciated.

TIA,

--
Fritz
Nov 16 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Fritz,
Can you give a more complete example of what you are doing, and what you
expect?

As using the following:

Debug.WriteLine(DateTime.Now.AddMinutes(30), "30");
Debug.WriteLine(DateTime.Now.AddMinutes(90), "90");
Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");

I get:

30: 7/19/2004 11:07:57 AM
90: 7/19/2004 12:07:57 PM
-45: 7/19/2004 9:52:57 AM

To limit the returned value to HH:MM I would use the ToString method with a
custom format, something like:

Debug.WriteLine(DateTime.Now.AddMinutes(30).ToStri ng("hh:mm"), "30")
Debug.WriteLine(DateTime.Now.AddMinutes(90).ToStri ng("hh:mm"), "90")
Debug.WriteLine(DateTime.Now.AddMinutes(-45).ToString("hh:mm"),
"-45")

30: 11:10
90: 12:10
-45: 09:55

For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay


"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
I'd like to have a string assigned the value of a
DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM"
format.

For example:

DateTime.Now.AddMinutes(30) returns "00:30"

DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"

DateTime.Now.AdMinutes(-45)) returns "-00:45"

I've tried all kinds of Format specifiers and nothing is working, any help
is appreciated.

TIA,

--
Fritz

Nov 16 '05 #2

P: n/a
Sounds like you want to be using the timespan.

Ex:
TimeSpan ts = DateTime.Now.AddMinutes(30) - DateTime.Now;
string output = ts.ToString("hh:mm");

--
Adam Clauss
ca*****@tamu.edu
"Fritz Switzer" <fr***********@abletfactory.com> wrote in message news:u1**************@TK2MSFTNGP10.phx.gbl...
I'd like to have a string assigned the value of a
DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM"
format.

For example:

DateTime.Now.AddMinutes(30) returns "00:30"

DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"

DateTime.Now.AdMinutes(-45)) returns "-00:45"

I've tried all kinds of Format specifiers and nothing is working, any help
is appreciated.

TIA,

--
Fritz

Nov 16 '05 #3

P: n/a
Adam,
As a short hand to " - DateTime.Now" you can use DateTime.TimeOfDay.
TimeSpan ts = DateTime.Now.AddMinutes(30).TimeOfDay;
string output = ts.ToString();
More importantly TimeSpan.ToString does not have any overloads, it returns
the value in a fixed format.

Hope this helps
Jay

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl... Sounds like you want to be using the timespan.

Ex:
TimeSpan ts = DateTime.Now.AddMinutes(30) - DateTime.Now;
string output = ts.ToString("hh:mm");

--
Adam Clauss
ca*****@tamu.edu
"Fritz Switzer" <fr***********@abletfactory.com> wrote in message

news:u1**************@TK2MSFTNGP10.phx.gbl...
I'd like to have a string assigned the value of a
DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM"
format.

For example:

DateTime.Now.AddMinutes(30) returns "00:30"

DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"

DateTime.Now.AdMinutes(-45)) returns "-00:45"

I've tried all kinds of Format specifiers and nothing is working, any help is appreciated.

TIA,

--
Fritz

Nov 16 '05 #4

P: n/a
Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Of**************@tk2msftngp13.phx.gbl...
Fritz,
Can you give a more complete example of what you are doing, and what you
expect?

Thanks Jay, here is more detail.

I'm using a random function that adds (- minutes) to the current time.
PickTime returns a negative number between 1-120. When the value is
returned the newTime is okay but just gives me total minutes , I just want
to format the result in hh:mm format. So if 95 minutes is returned I want
newTime to be "01:35" or if 46 is returned "00:46".

sting newTime =DateTime.Now.AddMinutes(-PickTime()).ToString();

So in your example:
Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
I'm looking to get 00:45 returned rather than.
-45: 7/19/2004 9:52:57 AM
It is being used as a "simulation", the value is attached to a timertick and
gets updated as time progresses. This seeds a value and the elapsed time is
updated with each tick, in this case, I'm updating a display every minute So
after 20 minutes the display using the above example of -45 I want the
value to be 01:05 (45+20 minutes or 1 hr 20 minutes)

hope that helps.





As using the following:

Debug.WriteLine(DateTime.Now.AddMinutes(30), "30");
Debug.WriteLine(DateTime.Now.AddMinutes(90), "90");
Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");

I get:

30: 7/19/2004 11:07:57 AM
90: 7/19/2004 12:07:57 PM
-45: 7/19/2004 9:52:57 AM

To limit the returned value to HH:MM I would use the ToString method with a custom format, something like:

Debug.WriteLine(DateTime.Now.AddMinutes(30).ToStri ng("hh:mm"), "30") Debug.WriteLine(DateTime.Now.AddMinutes(90).ToStri ng("hh:mm"), "90") Debug.WriteLine(DateTime.Now.AddMinutes(-45).ToString("hh:mm"),
"-45")

30: 11:10
90: 12:10
-45: 09:55

For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp
For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp
Hope this helps
Jay


"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
I'd like to have a string assigned the value of a
DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM"
format.

For example:

DateTime.Now.AddMinutes(30) returns "00:30"

DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"

DateTime.Now.AdMinutes(-45)) returns "-00:45"

I've tried all kinds of Format specifiers and nothing is working, any help is appreciated.

TIA,

--
Fritz


Nov 16 '05 #5

P: n/a
Ahh... my mistake, I glanced at the MSDN docs on it too quickly (I saw the table listing the different parts, assumed it was
overloaded). Odd, though, that they did not overload it in the same manner as DateTime.

--
Adam Clauss
ca*****@tamu.edu
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:Ox**************@TK2MSFTNGP10.phx.gbl...
Adam,
As a short hand to " - DateTime.Now" you can use DateTime.TimeOfDay.
TimeSpan ts = DateTime.Now.AddMinutes(30).TimeOfDay;
string output = ts.ToString();


More importantly TimeSpan.ToString does not have any overloads, it returns
the value in a fixed format.

Hope this helps
Jay

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
Sounds like you want to be using the timespan.

Ex:
TimeSpan ts = DateTime.Now.AddMinutes(30) - DateTime.Now;
string output = ts.ToString("hh:mm");

--
Adam Clauss
ca*****@tamu.edu
"Fritz Switzer" <fr***********@abletfactory.com> wrote in message

news:u1**************@TK2MSFTNGP10.phx.gbl...
I'd like to have a string assigned the value of a
DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM"
format.

For example:

DateTime.Now.AddMinutes(30) returns "00:30"

DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"

DateTime.Now.AdMinutes(-45)) returns "-00:45"

I've tried all kinds of Format specifiers and nothing is working, any help is appreciated.

TIA,

--
Fritz



Nov 16 '05 #6

P: n/a
Fritz,
I still don't follow you.

If your function returns 95, do you literally want "01:35" or do you want
"09:52" (which is Now - 95 minutes).

It sounds like you want "01:35", in which case you do not want to do
anything with DateTime.Now!

I would simply add minutes to DateTime.MinValue:

string newTime =
DateTime.MinValue.AddMinutes(PickTime()).ToString( "hh:mm");

If you want "09:52" (Now - 95 minutes), then use DateTime.Now:

sting newTime =DateTime.Now.AddMinutes(-PickTime()).ToString("hh:mm");

If you have a specific time in mind, then use it:

DateTime whenever;
sting newTime =whenever.AddMinutes(-PickTime()).ToString("hh:mm");

In either case to the time formatted, you need to use
DateTime.ToString("hh:mm"), see my first reply for details on formatting.

Hope this helps
Jay

"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl...
Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Of**************@tk2msftngp13.phx.gbl...
Fritz,
Can you give a more complete example of what you are doing, and what you
expect?

Thanks Jay, here is more detail.

I'm using a random function that adds (- minutes) to the current time.
PickTime returns a negative number between 1-120. When the value is
returned the newTime is okay but just gives me total minutes , I just want
to format the result in hh:mm format. So if 95 minutes is returned I want
newTime to be "01:35" or if 46 is returned "00:46".

sting newTime =DateTime.Now.AddMinutes(-PickTime()).ToString();

So in your example:
Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");


I'm looking to get 00:45 returned rather than.
-45: 7/19/2004 9:52:57 AM


It is being used as a "simulation", the value is attached to a timertick

and gets updated as time progresses. This seeds a value and the elapsed time is updated with each tick, in this case, I'm updating a display every minute So after 20 minutes the display using the above example of -45 I want the
value to be 01:05 (45+20 minutes or 1 hr 20 minutes)

hope that helps.





As using the following:

Debug.WriteLine(DateTime.Now.AddMinutes(30), "30");
Debug.WriteLine(DateTime.Now.AddMinutes(90), "90");
Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");

I get:

30: 7/19/2004 11:07:57 AM
90: 7/19/2004 12:07:57 PM
-45: 7/19/2004 9:52:57 AM

To limit the returned value to HH:MM I would use the ToString method with
a
custom format, something like:

Debug.WriteLine(DateTime.Now.AddMinutes(30).ToStri ng("hh:mm"),

"30")
Debug.WriteLine(DateTime.Now.AddMinutes(90).ToStri ng("hh:mm"),

"90")
Debug.WriteLine(DateTime.Now.AddMinutes(-45).ToString("hh:mm"),
"-45")

30: 11:10
90: 12:10
-45: 09:55

For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

For information on formatting in .NET in general see:

http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay


"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
I'd like to have a string assigned the value of a
DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM"
format.

For example:

DateTime.Now.AddMinutes(30) returns "00:30"

DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"

DateTime.Now.AdMinutes(-45)) returns "-00:45"

I've tried all kinds of Format specifiers and nothing is working, any

help is appreciated.

TIA,

--
Fritz



Nov 16 '05 #7

P: n/a
Adam,
Odd, though, that they did not overload it in the same manner as DateTime. I would expect it to be overloaded also, as sometimes I want to custom
format the Timespan, as this example just hours & minutes (no seconds).

Maybe we'll have to submit a suggestion for VS.NET 2005 at:

http://lab.msdn.microsoft.com/vs2005/

Jay

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:e$****************@TK2MSFTNGP10.phx.gbl... Ahh... my mistake, I glanced at the MSDN docs on it too quickly (I saw the table listing the different parts, assumed it was overloaded). Odd, though, that they did not overload it in the same manner as DateTime.
--
Adam Clauss
ca*****@tamu.edu
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message

news:Ox**************@TK2MSFTNGP10.phx.gbl...
Adam,
As a short hand to " - DateTime.Now" you can use DateTime.TimeOfDay.
TimeSpan ts = DateTime.Now.AddMinutes(30).TimeOfDay;
string output = ts.ToString();


More importantly TimeSpan.ToString does not have any overloads, it returns the value in a fixed format.

Hope this helps
Jay

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
Sounds like you want to be using the timespan.

Ex:
TimeSpan ts = DateTime.Now.AddMinutes(30) - DateTime.Now;
string output = ts.ToString("hh:mm");

--
Adam Clauss
ca*****@tamu.edu
"Fritz Switzer" <fr***********@abletfactory.com> wrote in message

news:u1**************@TK2MSFTNGP10.phx.gbl...
> I'd like to have a string assigned the value of a
> DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" > format.
>
> For example:
>
> DateTime.Now.AddMinutes(30) returns "00:30"
>
> DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
>
> DateTime.Now.AdMinutes(-45)) returns "-00:45"
>
> I've tried all kinds of Format specifiers and nothing is working,
any help
> is appreciated.
>
> TIA,
>
> --
> Fritz
>
>


Nov 16 '05 #8

P: n/a
Thanks Jay/Adam,

If your function returns 95, do you literally want "01:35" or do you want
"09:52" (which is Now - 95 minutes).
I want "01:35"

It sounds like you want "01:35", in which case you do not want to do
anything with DateTime.Now!

Here are some additional details. I'm simulating a "doctors office", I want
to display the length in time (in "hh:mm") someone is waiting. I first
start by randomly assigning a time from -(1-120 minutes) so I use
DateTime.Now.AddMinutes(negative random amount). This then gives me length
of time, I'm just using minutes. So patient 1 = 35 minutes, patient 2= 65
minutes patient 3= 90 minutes . Now I need to display the time in a grid
control with the waiting time in "hh:mm" format, and just to make things
more complicated also sorted by longest wait time to shortest wait time.
So I can get 01:30, 01:05, and 00:35. After two minutes the display should
read 01:32, 01:07, 00:37. A timer is updating the display every minute.

hope that clears up things,

Thanks, appreciate the help.

Fritz

In either case to the time formatted, you need to use
DateTime.ToString("hh:mm"), see my first reply for details on formatting.


Hope this helps
Jay

"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl...
Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Of**************@tk2msftngp13.phx.gbl...
Fritz,
Can you give a more complete example of what you are doing, and what you expect?

Thanks Jay, here is more detail.

I'm using a random function that adds (- minutes) to the current time.
PickTime returns a negative number between 1-120. When the value is
returned the newTime is okay but just gives me total minutes , I just want
to format the result in hh:mm format. So if 95 minutes is returned I want newTime to be "01:35" or if 46 is returned "00:46".

sting newTime =DateTime.Now.AddMinutes(-PickTime()).ToString();

So in your example:
Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");


I'm looking to get 00:45 returned rather than.
-45: 7/19/2004 9:52:57 AM


It is being used as a "simulation", the value is attached to a timertick

and
gets updated as time progresses. This seeds a value and the elapsed time

is
updated with each tick, in this case, I'm updating a display every minute So
after 20 minutes the display using the above example of -45 I want the
value to be 01:05 (45+20 minutes or 1 hr 20 minutes)

hope that helps.





As using the following:

Debug.WriteLine(DateTime.Now.AddMinutes(30), "30");
Debug.WriteLine(DateTime.Now.AddMinutes(90), "90");
Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");

I get:

30: 7/19/2004 11:07:57 AM
90: 7/19/2004 12:07:57 PM
-45: 7/19/2004 9:52:57 AM

To limit the returned value to HH:MM I would use the ToString method

with
a
custom format, something like:

Debug.WriteLine(DateTime.Now.AddMinutes(30).ToStri ng("hh:mm"),

"30")
Debug.WriteLine(DateTime.Now.AddMinutes(90).ToStri ng("hh:mm"),

"90")
Debug.WriteLine(DateTime.Now.AddMinutes(-45).ToString("hh:mm"), "-45")

30: 11:10
90: 12:10
-45: 09:55

For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

For information on formatting in .NET in general see:

http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay


"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
> I'd like to have a string assigned the value of a
> DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" > format.
>
> For example:
>
> DateTime.Now.AddMinutes(30) returns "00:30"
>
> DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
>
> DateTime.Now.AdMinutes(-45)) returns "-00:45"
>
> I've tried all kinds of Format specifiers and nothing is working,

any help
> is appreciated.
>
> TIA,
>
> --
> Fritz
>
>



Nov 16 '05 #9

P: n/a
Fritz,
I have to ask, is this a home work assignment? Your questions & troubles
make this sounds suspiciously like a home work assignment. If it is I
strongly recommend you stop "cheating", if not, my apologies, proceed. Thank
you for understanding either way.

It really sounds like you are confusing:
- current time
- entry time
- elapsed time

As Now.AddMinutes(negative) will simulate entry time.

Now will simulate current time.

elapsed time = entry time - current time

It sounds like you want your grid to display elapsed time.

I would consider binding your Grid Control to a custom object, that has two
properties, as the custom object will allow you to easily update the elapsed
time value.

This custom object would need an Entry & an Elapsed property. Where you set
Entry to your Now.AddMinutes(negative), and Elapsed is Now.Subtract(Entry)

Note DateTime.Subtract will give you a TimeSpan, which you cannot custom
format, if you only want Elapsed to show hours & minutes I would add the
TimeSpan to DateTime.MinValue to convert it back to a DateTime...

Alternatively you could bind to a dataset, where you use a timer object and
& for loop to update the elapsed column of each row...

Hope this helps
Jay

"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
Thanks Jay/Adam,

If your function returns 95, do you literally want "01:35" or do you want
"09:52" (which is Now - 95 minutes).
I want "01:35"

It sounds like you want "01:35", in which case you do not want to do
anything with DateTime.Now!


Here are some additional details. I'm simulating a "doctors office", I

want to display the length in time (in "hh:mm") someone is waiting. I first
start by randomly assigning a time from -(1-120 minutes) so I use
DateTime.Now.AddMinutes(negative random amount). This then gives me length of time, I'm just using minutes. So patient 1 = 35 minutes, patient 2= 65
minutes patient 3= 90 minutes . Now I need to display the time in a grid control with the waiting time in "hh:mm" format, and just to make things
more complicated also sorted by longest wait time to shortest wait time.
So I can get 01:30, 01:05, and 00:35. After two minutes the display should read 01:32, 01:07, 00:37. A timer is updating the display every minute.

hope that clears up things,

Thanks, appreciate the help.

Fritz

In either case to the time formatted, you need to use
DateTime.ToString("hh:mm"), see my first reply for details on formatting.



Hope this helps
Jay

"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl...
Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:Of**************@tk2msftngp13.phx.gbl...
> Fritz,
> Can you give a more complete example of what you are doing, and what

you > expect?
>

Thanks Jay, here is more detail.

I'm using a random function that adds (- minutes) to the current time.
PickTime returns a negative number between 1-120. When the value is
returned the newTime is okay but just gives me total minutes , I just want to format the result in hh:mm format. So if 95 minutes is returned I want newTime to be "01:35" or if 46 is returned "00:46".

sting newTime =DateTime.Now.AddMinutes(-PickTime()).ToString();

So in your example:

> Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");

I'm looking to get 00:45 returned rather than.

> -45: 7/19/2004 9:52:57 AM

It is being used as a "simulation", the value is attached to a timertick and
gets updated as time progresses. This seeds a value and the elapsed
time
is
updated with each tick, in this case, I'm updating a display every

minute
So
after 20 minutes the display using the above example of -45 I want

the value to be 01:05 (45+20 minutes or 1 hr 20 minutes)

hope that helps.






> As using the following:
>
> Debug.WriteLine(DateTime.Now.AddMinutes(30), "30");
> Debug.WriteLine(DateTime.Now.AddMinutes(90), "90");
> Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
>
> I get:
>
> 30: 7/19/2004 11:07:57 AM
> 90: 7/19/2004 12:07:57 PM
> -45: 7/19/2004 9:52:57 AM
>
> To limit the returned value to HH:MM I would use the ToString method

with
a
> custom format, something like:
>
> Debug.WriteLine(DateTime.Now.AddMinutes(30).ToStri ng("hh:mm"), "30")
> Debug.WriteLine(DateTime.Now.AddMinutes(90).ToStri ng("hh:mm"), "90")
>

Debug.WriteLine(DateTime.Now.AddMinutes(-45).ToString("hh:mm"), > "-45")
>
> 30: 11:10
> 90: 12:10
> -45: 09:55
>
> For details on custom datetime formats see:
>
>

http://msdn.microsoft.com/library/de...matstrings.asp
>
> For information on formatting in .NET in general see:
>

http://msdn.microsoft.com/library/de...ttingtypes.asp
>
> Hope this helps
> Jay
>
>
>
>
> "Fritz Switzer" <fr***********@abletfactory.com> wrote in message
> news:u1**************@TK2MSFTNGP10.phx.gbl...
> > I'd like to have a string assigned the value of a
> > DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" > > format.
> >
> > For example:
> >
> > DateTime.Now.AddMinutes(30) returns "00:30"
> >
> > DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
> >
> > DateTime.Now.AdMinutes(-45)) returns "-00:45"
> >
> > I've tried all kinds of Format specifiers and nothing is working, any help
> > is appreciated.
> >
> > TIA,
> >
> > --
> > Fritz
> >
> >
>
>



Nov 16 '05 #10

P: n/a
Jay/Adam,

Not a "homework" assignment, real work. No apologies necessary and I
understand.

The requirement is for a grid control to show an elapsed time formatted in
"hh:mm", with the time in descending order. During development, I need to
simulate elapsed time, hence the seeding with the previous times for testing
only.

The confusion is finding the correct formating for "strings", "DateTime" and
"TimeSpan" and doing the calculations to show the elapsed time in "hh:mm".

The suggestions from both Jay and Adam have very been helpful.

Much appreciated.

--
Fritz
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OI****************@TK2MSFTNGP12.phx.gbl...
Fritz,
I have to ask, is this a home work assignment? Your questions & troubles
make this sounds suspiciously like a home work assignment. If it is I
strongly recommend you stop "cheating", if not, my apologies, proceed. Thank you for understanding either way.

It really sounds like you are confusing:
- current time
- entry time
- elapsed time

As Now.AddMinutes(negative) will simulate entry time.

Now will simulate current time.

elapsed time = entry time - current time

It sounds like you want your grid to display elapsed time.

I would consider binding your Grid Control to a custom object, that has two properties, as the custom object will allow you to easily update the elapsed time value.

This custom object would need an Entry & an Elapsed property. Where you set Entry to your Now.AddMinutes(negative), and Elapsed is Now.Subtract(Entry)
Note DateTime.Subtract will give you a TimeSpan, which you cannot custom
format, if you only want Elapsed to show hours & minutes I would add the
TimeSpan to DateTime.MinValue to convert it back to a DateTime...

Alternatively you could bind to a dataset, where you use a timer object and & for loop to update the elapsed column of each row...

Hope this helps
Jay

"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
Thanks Jay/Adam,

If your function returns 95, do you literally want "01:35" or do you want "09:52" (which is Now - 95 minutes).


I want "01:35"

It sounds like you want "01:35", in which case you do not want to do
anything with DateTime.Now!


Here are some additional details. I'm simulating a "doctors office", I

want
to display the length in time (in "hh:mm") someone is waiting. I first
start by randomly assigning a time from -(1-120 minutes) so I use
DateTime.Now.AddMinutes(negative random amount). This then gives me

length
of time, I'm just using minutes. So patient 1 = 35 minutes, patient 2= 65
minutes patient 3= 90 minutes . Now I need to display the time in a

grid
control with the waiting time in "hh:mm" format, and just to make things more complicated also sorted by longest wait time to shortest wait time. So I can get 01:30, 01:05, and 00:35. After two minutes the display

should
read 01:32, 01:07, 00:37. A timer is updating the display every minute.

hope that clears up things,

Thanks, appreciate the help.

Fritz

In either case to the time formatted, you need to use
DateTime.ToString("hh:mm"), see my first reply for details on formatting.



Hope this helps
Jay

"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl...
> Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in

message > news:Of**************@tk2msftngp13.phx.gbl...
> > Fritz,
> > Can you give a more complete example of what you are doing, and what you
> > expect?
> >
>
> Thanks Jay, here is more detail.
>
> I'm using a random function that adds (- minutes) to the current
time. > PickTime returns a negative number between 1-120. When the value is
> returned the newTime is okay but just gives me total minutes , I just
want
> to format the result in hh:mm format. So if 95 minutes is returned
I want
> newTime to be "01:35" or if 46 is returned "00:46".
>
> sting newTime =DateTime.Now.AddMinutes(-PickTime()).ToString();
>
> So in your example:
>
> > Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
>
> I'm looking to get 00:45 returned rather than.
>
> > -45: 7/19/2004 9:52:57 AM
>
>
>
> It is being used as a "simulation", the value is attached to a timertick and
> gets updated as time progresses. This seeds a value and the elapsed time is
> updated with each tick, in this case, I'm updating a display every

minute
So
> after 20 minutes the display using the above example of -45 I want the > value to be 01:05 (45+20 minutes or 1 hr 20 minutes)
>
> hope that helps.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> > As using the following:
> >
> > Debug.WriteLine(DateTime.Now.AddMinutes(30), "30");
> > Debug.WriteLine(DateTime.Now.AddMinutes(90), "90");
> > Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
> >
> > I get:
> >
> > 30: 7/19/2004 11:07:57 AM
> > 90: 7/19/2004 12:07:57 PM
> > -45: 7/19/2004 9:52:57 AM
> >
> > To limit the returned value to HH:MM I would use the ToString
method with
> a
> > custom format, something like:
> >
> >

Debug.WriteLine(DateTime.Now.AddMinutes(30).ToStri ng("hh:mm"), > "30")
> > Debug.WriteLine(DateTime.Now.AddMinutes(90).ToStri ng("hh:mm"), > "90")
> >

Debug.WriteLine(DateTime.Now.AddMinutes(-45).ToString("hh:mm"),
> > "-45")
> >
> > 30: 11:10
> > 90: 12:10
> > -45: 09:55
> >
> > For details on custom datetime formats see:
> >
> >
>

http://msdn.microsoft.com/library/de...matstrings.asp
> >
> > For information on formatting in .NET in general see:
> >
>

http://msdn.microsoft.com/library/de...ttingtypes.asp
> >
> > Hope this helps
> > Jay
> >
> >
> >
> >
> > "Fritz Switzer" <fr***********@abletfactory.com> wrote in message
> > news:u1**************@TK2MSFTNGP10.phx.gbl...
> > > I'd like to have a string assigned the value of a
> > > DateTime.AddMinutes(amount) so that the string is formatted in

"HH:MM"
> > > format.
> > >
> > > For example:
> > >
> > > DateTime.Now.AddMinutes(30) returns "00:30"
> > >
> > > DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
> > >
> > > DateTime.Now.AdMinutes(-45)) returns "-00:45"
> > >
> > > I've tried all kinds of Format specifiers and nothing is

working, any
> help
> > > is appreciated.
> > >
> > > TIA,
> > >
> > > --
> > > Fritz
> > >
> > >
> >
> >
>
>



Nov 16 '05 #11

P: n/a
Fritz,
Neither "String" nor "TimeSpan" support custom formatting. So your elapsed
time will need to be a DateTime. If you make it a DateTime, you can use
"hh:mm" for the format. Note it needs to be lower case, as "MM" is months...

Post if you really need help in how to get the grid to use your formatting.

Hope this helps
Jay
"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...
Jay/Adam,

Not a "homework" assignment, real work. No apologies necessary and I
understand.

The requirement is for a grid control to show an elapsed time formatted in
"hh:mm", with the time in descending order. During development, I need to
simulate elapsed time, hence the seeding with the previous times for testing only.

The confusion is finding the correct formating for "strings", "DateTime" and "TimeSpan" and doing the calculations to show the elapsed time in "hh:mm".

The suggestions from both Jay and Adam have very been helpful.

Much appreciated.

--
Fritz
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OI****************@TK2MSFTNGP12.phx.gbl...
Fritz,
I have to ask, is this a home work assignment? Your questions & troubles
make this sounds suspiciously like a home work assignment. If it is I
strongly recommend you stop "cheating", if not, my apologies, proceed. Thank
you for understanding either way.

It really sounds like you are confusing:
- current time
- entry time
- elapsed time

As Now.AddMinutes(negative) will simulate entry time.

Now will simulate current time.

elapsed time = entry time - current time

It sounds like you want your grid to display elapsed time.

I would consider binding your Grid Control to a custom object, that has

two
properties, as the custom object will allow you to easily update the

elapsed
time value.

This custom object would need an Entry & an Elapsed property. Where you

set
Entry to your Now.AddMinutes(negative), and Elapsed is

Now.Subtract(Entry)

Note DateTime.Subtract will give you a TimeSpan, which you cannot custom
format, if you only want Elapsed to show hours & minutes I would add the
TimeSpan to DateTime.MinValue to convert it back to a DateTime...

Alternatively you could bind to a dataset, where you use a timer object

and
& for loop to update the elapsed column of each row...

Hope this helps
Jay

"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
Thanks Jay/Adam,
> If your function returns 95, do you literally want "01:35" or do you

want
> "09:52" (which is Now - 95 minutes).

I want "01:35"

>
> It sounds like you want "01:35", in which case you do not want to do
> anything with DateTime.Now!
>

Here are some additional details. I'm simulating a "doctors office", I
want
to display the length in time (in "hh:mm") someone is waiting. I
first start by randomly assigning a time from -(1-120 minutes) so I use
DateTime.Now.AddMinutes(negative random amount). This then gives me

length
of time, I'm just using minutes. So patient 1 = 35 minutes, patient 2= 65 minutes patient 3= 90 minutes . Now I need to display the time in a grid
control with the waiting time in "hh:mm" format, and just to make things more complicated also sorted by longest wait time to shortest wait time. So I can get 01:30, 01:05, and 00:35. After two minutes the display

should
read 01:32, 01:07, 00:37. A timer is updating the display every
minute.
hope that clears up things,

Thanks, appreciate the help.

Fritz


> In either case to the time formatted, you need to use
> DateTime.ToString("hh:mm"), see my first reply for details on

formatting.



>
> Hope this helps
> Jay
>
> "Fritz Switzer" <fr***********@abletfactory.com> wrote in message
> news:eZ**************@TK2MSFTNGP10.phx.gbl...
> > Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in

message
> > news:Of**************@tk2msftngp13.phx.gbl...
> > > Fritz,
> > > Can you give a more complete example of what you are doing, and what you
> > > expect?
> > >
> >
> > Thanks Jay, here is more detail.
> >
> > I'm using a random function that adds (- minutes) to the current time. > > PickTime returns a negative number between 1-120. When the value is > > returned the newTime is okay but just gives me total minutes , I just want
> > to format the result in hh:mm format. So if 95 minutes is returned I
want
> > newTime to be "01:35" or if 46 is returned "00:46".
> >
> > sting newTime =DateTime.Now.AddMinutes(-PickTime()).ToString();
> >
> > So in your example:
> >
> > > Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
> >
> > I'm looking to get 00:45 returned rather than.
> >
> > > -45: 7/19/2004 9:52:57 AM
> >
> >
> >
> > It is being used as a "simulation", the value is attached to a

timertick
> and
> > gets updated as time progresses. This seeds a value and the
elapsed time
> is
> > updated with each tick, in this case, I'm updating a display every
minute
> So
> > after 20 minutes the display using the above example of -45 I
want the
> > value to be 01:05 (45+20 minutes or 1 hr 20 minutes)
> >
> > hope that helps.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > As using the following:
> > >
> > > Debug.WriteLine(DateTime.Now.AddMinutes(30), "30");
> > > Debug.WriteLine(DateTime.Now.AddMinutes(90), "90");
> > > Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
> > >
> > > I get:
> > >
> > > 30: 7/19/2004 11:07:57 AM
> > > 90: 7/19/2004 12:07:57 PM
> > > -45: 7/19/2004 9:52:57 AM
> > >
> > > To limit the returned value to HH:MM I would use the ToString

method > with
> > a
> > > custom format, something like:
> > >
> > >

Debug.WriteLine(DateTime.Now.AddMinutes(30).ToStri ng("hh:mm"),
> > "30")
> > >

Debug.WriteLine(DateTime.Now.AddMinutes(90).ToStri ng("hh:mm"),
> > "90")
> > >
Debug.WriteLine(DateTime.Now.AddMinutes(-45).ToString("hh:mm"),
> > > "-45")
> > >
> > > 30: 11:10
> > > 90: 12:10
> > > -45: 09:55
> > >
> > > For details on custom datetime formats see:
> > >
> > >
> >
>

http://msdn.microsoft.com/library/de...matstrings.asp > > >
> > > For information on formatting in .NET in general see:
> > >
> >
>

http://msdn.microsoft.com/library/de...ttingtypes.asp
> > >
> > > Hope this helps
> > > Jay
> > >
> > >
> > >
> > >
> > > "Fritz Switzer" <fr***********@abletfactory.com> wrote in message > > > news:u1**************@TK2MSFTNGP10.phx.gbl...
> > > > I'd like to have a string assigned the value of a
> > > > DateTime.AddMinutes(amount) so that the string is formatted in
"HH:MM"
> > > > format.
> > > >
> > > > For example:
> > > >
> > > > DateTime.Now.AddMinutes(30) returns "00:30"
> > > >
> > > > DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
> > > >
> > > > DateTime.Now.AdMinutes(-45)) returns "-00:45"
> > > >
> > > > I've tried all kinds of Format specifiers and nothing is working, any
> > help
> > > > is appreciated.
> > > >
> > > > TIA,
> > > >
> > > > --
> > > > Fritz
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 16 '05 #12

P: n/a
Jay,

Thanks for the help, I'll keep everything DateTime for now. That should
make the grid issue simpler.

Much appreciated.

--
Fritz

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eb**************@TK2MSFTNGP10.phx.gbl...
Fritz,
Neither "String" nor "TimeSpan" support custom formatting. So your elapsed
time will need to be a DateTime. If you make it a DateTime, you can use
"hh:mm" for the format. Note it needs to be lower case, as "MM" is months...
Post if you really need help in how to get the grid to use your formatting.
Hope this helps
Jay
"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:uO*************@tk2msftngp13.phx.gbl...
Jay/Adam,

Not a "homework" assignment, real work. No apologies necessary and I
understand.

The requirement is for a grid control to show an elapsed time formatted in
"hh:mm", with the time in descending order. During development, I need to simulate elapsed time, hence the seeding with the previous times for testing
only.

The confusion is finding the correct formating for "strings", "DateTime"

and
"TimeSpan" and doing the calculations to show the elapsed time in "hh:mm".
The suggestions from both Jay and Adam have very been helpful.

Much appreciated.

--
Fritz
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:OI****************@TK2MSFTNGP12.phx.gbl...
Fritz,
I have to ask, is this a home work assignment? Your questions & troubles make this sounds suspiciously like a home work assignment. If it is I
strongly recommend you stop "cheating", if not, my apologies, proceed.

Thank
you for understanding either way.

It really sounds like you are confusing:
- current time
- entry time
- elapsed time

As Now.AddMinutes(negative) will simulate entry time.

Now will simulate current time.

elapsed time = entry time - current time

It sounds like you want your grid to display elapsed time.

I would consider binding your Grid Control to a custom object, that has
two
properties, as the custom object will allow you to easily update the

elapsed
time value.

This custom object would need an Entry & an Elapsed property. Where
you set
Entry to your Now.AddMinutes(negative), and Elapsed is

Now.Subtract(Entry)

Note DateTime.Subtract will give you a TimeSpan, which you cannot
custom format, if you only want Elapsed to show hours & minutes I would add the TimeSpan to DateTime.MinValue to convert it back to a DateTime...

Alternatively you could bind to a dataset, where you use a timer object and
& for loop to update the elapsed column of each row...

Hope this helps
Jay

"Fritz Switzer" <fr***********@abletfactory.com> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
> Thanks Jay/Adam,
>
>
> > If your function returns 95, do you literally want "01:35" or do
you want
> > "09:52" (which is Now - 95 minutes).
>
> I want "01:35"
>
> >
> > It sounds like you want "01:35", in which case you do not want to do > > anything with DateTime.Now!
> >
>
> Here are some additional details. I'm simulating a "doctors office", I want
> to display the length in time (in "hh:mm") someone is waiting. I first > start by randomly assigning a time from -(1-120 minutes) so I use
> DateTime.Now.AddMinutes(negative random amount). This then gives me
length
> of time, I'm just using minutes. So patient 1 = 35 minutes, patient 2=
65
> minutes patient 3= 90 minutes . Now I need to display the time in
a grid
> control with the waiting time in "hh:mm" format, and just to make

things
> more complicated also sorted by longest wait time to shortest wait

time.
> So I can get 01:30, 01:05, and 00:35. After two minutes the display
should
> read 01:32, 01:07, 00:37. A timer is updating the display every

minute. >
> hope that clears up things,
>
> Thanks, appreciate the help.
>
> Fritz
>
>
>
>
> > In either case to the time formatted, you need to use
> > DateTime.ToString("hh:mm"), see my first reply for details on
formatting.
>
>
>
>
>
> >
> > Hope this helps
> > Jay
> >
> > "Fritz Switzer" <fr***********@abletfactory.com> wrote in message
> > news:eZ**************@TK2MSFTNGP10.phx.gbl...
> > > Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message
> > > news:Of**************@tk2msftngp13.phx.gbl...
> > > > Fritz,
> > > > Can you give a more complete example of what you are doing, and what
> you
> > > > expect?
> > > >
> > >
> > > Thanks Jay, here is more detail.
> > >
> > > I'm using a random function that adds (- minutes) to the current

time.
> > > PickTime returns a negative number between 1-120. When the
value is > > > returned the newTime is okay but just gives me total minutes , I

just
> want
> > > to format the result in hh:mm format. So if 95 minutes is returned
I
> want
> > > newTime to be "01:35" or if 46 is returned "00:46".
> > >
> > > sting newTime =DateTime.Now.AddMinutes(-PickTime()).ToString();
> > >
> > > So in your example:
> > >
> > > > Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
> > >
> > > I'm looking to get 00:45 returned rather than.
> > >
> > > > -45: 7/19/2004 9:52:57 AM
> > >
> > >
> > >
> > > It is being used as a "simulation", the value is attached to a
timertick
> > and
> > > gets updated as time progresses. This seeds a value and the

elapsed time
> > is
> > > updated with each tick, in this case, I'm updating a display
every > minute
> > So
> > > after 20 minutes the display using the above example of -45 I

want the
> > > value to be 01:05 (45+20 minutes or 1 hr 20 minutes)
> > >
> > > hope that helps.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > > As using the following:
> > > >
> > > > Debug.WriteLine(DateTime.Now.AddMinutes(30), "30");
> > > > Debug.WriteLine(DateTime.Now.AddMinutes(90), "90");
> > > > Debug.WriteLine(DateTime.Now.AddMinutes(-45), "-45");
> > > >
> > > > I get:
> > > >
> > > > 30: 7/19/2004 11:07:57 AM
> > > > 90: 7/19/2004 12:07:57 PM
> > > > -45: 7/19/2004 9:52:57 AM
> > > >
> > > > To limit the returned value to HH:MM I would use the ToString

method
> > with
> > > a
> > > > custom format, something like:
> > > >
> > > >
Debug.WriteLine(DateTime.Now.AddMinutes(30).ToStri ng("hh:mm"),
> > > "30")
> > > >
Debug.WriteLine(DateTime.Now.AddMinutes(90).ToStri ng("hh:mm"),
> > > "90")
> > > >
> Debug.WriteLine(DateTime.Now.AddMinutes(-45).ToString("hh:mm"),
> > > > "-45")
> > > >
> > > > 30: 11:10
> > > > 90: 12:10
> > > > -45: 09:55
> > > >
> > > > For details on custom datetime formats see:
> > > >
> > > >
> > >
> >
>

http://msdn.microsoft.com/library/de...matstrings.asp
> > > >
> > > > For information on formatting in .NET in general see:
> > > >
> > >
> >
>

http://msdn.microsoft.com/library/de...ttingtypes.asp
> > > >
> > > > Hope this helps
> > > > Jay
> > > >
> > > >
> > > >
> > > >
> > > > "Fritz Switzer" <fr***********@abletfactory.com> wrote in message > > > > news:u1**************@TK2MSFTNGP10.phx.gbl...
> > > > > I'd like to have a string assigned the value of a
> > > > > DateTime.AddMinutes(amount) so that the string is formatted in > "HH:MM"
> > > > > format.
> > > > >
> > > > > For example:
> > > > >
> > > > > DateTime.Now.AddMinutes(30) returns "00:30"
> > > > >
> > > > > DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
> > > > >
> > > > > DateTime.Now.AdMinutes(-45)) returns "-00:45"
> > > > >
> > > > > I've tried all kinds of Format specifiers and nothing is

working,
> any
> > > help
> > > > > is appreciated.
> > > > >
> > > > > TIA,
> > > > >
> > > > > --
> > > > > Fritz
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 16 '05 #13

P: n/a
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eb**************@TK2MSFTNGP10.phx.gbl...
Fritz,
Neither "String" nor "TimeSpan" support custom formatting. So your elapsed
time will need to be a DateTime. If you make it a DateTime, you can use
"hh:mm" for the format. Note it needs to be lower case, as "MM" is months...


Or - you can still use a TimeSpan -

TimeSpan ts = .....
string output = string.Format("%2d:%2d", ts.Hours, ts.Minutes);

That should give the format you want right?
--
Adam Clauss
ca*****@tamu.edu
Nov 16 '05 #14

P: n/a
Adam,
Not if your binding to a grid, unless you want to override the Format &
Parse events.

With all the trouble Fritz appears to be having I don't think its advisable
to push him toward a triathlon...

In other words yes you can do it that way. I just wonder if Fritz should do
it that way.

Just a thought
Jay
"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eb**************@TK2MSFTNGP10.phx.gbl...
Fritz,
Neither "String" nor "TimeSpan" support custom formatting. So your elapsed time will need to be a DateTime. If you make it a DateTime, you can use
"hh:mm" for the format. Note it needs to be lower case, as "MM" is

months...
Or - you can still use a TimeSpan -

TimeSpan ts = .....
string output = string.Format("%2d:%2d", ts.Hours, ts.Minutes);

That should give the format you want right?
--
Adam Clauss
ca*****@tamu.edu

Nov 16 '05 #15

P: n/a
> With all the trouble Fritz appears to be having I don't think its
advisable
to push him toward a triathlon...
I only particpate in events that last less than an hour. 00:59 :)

--
Fritz

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eI**************@TK2MSFTNGP09.phx.gbl... Adam,
Not if your binding to a grid, unless you want to override the Format &
Parse events.

With all the trouble Fritz appears to be having I don't think its advisable to push him toward a triathlon...

In other words yes you can do it that way. I just wonder if Fritz should do it that way.

Just a thought
Jay
"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eb**************@TK2MSFTNGP10.phx.gbl... Fritz,
Neither "String" nor "TimeSpan" support custom formatting. So your elapsed time will need to be a DateTime. If you make it a DateTime, you can use "hh:mm" for the format. Note it needs to be lower case, as "MM" is

months...

Or - you can still use a TimeSpan -

TimeSpan ts = .....
string output = string.Format("%2d:%2d", ts.Hours, ts.Minutes);

That should give the format you want right?
--
Adam Clauss
ca*****@tamu.edu


Nov 16 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.