|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Format ProblemsCan someone help me on a format problem. I am trying to do this..
format a string to a number. The string has a number with a colon in the middle. Format("1:30","00:00") returns 00:00 instead of 01:30 How can this be done? Thanks BUC <Buc> schrieb
> Can someone help me on a format problem. I am trying to do this.. "00:00" is not a valid format string for formatting strings. You already> format a string to a number. The string has a number with a colon in > the middle. > > Format("1:30","00:00") > returns 00:00 instead of 01:30 > > How can this be done? have a string. See also: http://msdn.microsoft.com/library/en-us/cpguide/html/cpconworkingwithbasetypes.asp Armin "Tom McL." <tb***@cwnet.com> schrieb This doesn't compile. You can not assign a String to a Date variable. > Dim s As Date = "1:30" Switching Option Strict Off creates the risk of overlooking unintended implicit conversions. > Dim myTime As String Armin> > myTime = Format(s, "HH:mm") <Buc> wrote in message news:%2335SpG1JGHA.1760@TK2MSFTNGP10.phx.gbl... No you're not. You're trying to format a String into a String> I am trying to do this.. format a string to a number. The string has a > number with a colon in the middle. > Format("1:30","00:00") and "0" /isn't/ a valid formatting character when formatting a String ("@" is the only one I can think of). Try this: Format( CDate( "1:30" ),"00:00" ) Now that's taking a String, converting (CDate'ing) it to a Date, then formatting /that/ back into a string again, using the formatting rules for Dates and Times, as you'd expect. Or, better still, since you're working in VB.Net CDate( "1:30" ).ToString( "00:00" ) (OK, there's "better" ways of converting a string to a Date, but it's the "new" way of /formatting/ I'm trying to show). :-) HTH, Phill W. <Buc> wrote in news:#35SpG1JGHA.1760@TK2MSFTNGP10.phx.gbl: I still learning the dotNet way of doing this, but the old fashioned> Format("1:30","00:00") > returns 00:00 instead of 01:30 > > How can this be done? Right("00" & someTimeString, 5) would seem to get the right answer. Tim F |
|||||||||||||||||||||||