|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Time difference calculationI entered the following in my immediate window and expected to see a result of
4:00 Why is it showing me :12 ? I want to subtract the 2 date/times and get 4 hours as the result. Please help ?format(#2/2/2006 2:35:00 PM# -#2/2/2006 10:35:00 AM#,"[h]:mm") Show quoteHide quote :12 Paulymon wrote:
> I entered the following in my immediate window and expected to see a Huh. All I get is an error. <shrug>> result of 4:00 > > Why is it showing me :12 ? I want to subtract the 2 date/times and > get 4 hours as the result. > > Please help > > ?format(#2/2/2006 2:35:00 PM# -#2/2/2006 10:35:00 AM#,"[h]:mm") >> 12 You might want to look-up the DateDiff function in Help. ?datediff("h", #2/2/2006 2:35:00 PM# , #2/2/2006 10:35:00 AM#) -4 "Paulymon" <Pauly***@discussions.microsoft.com> wrote in message Then use DateDiff().news:EC777025-45BC-44CB-9BEE-BD6888DB26BF@microsoft.com... >I entered the following in my immediate window and expected to see a result >of > 4:00 > > Why is it showing me :12 ? I want to subtract the 2 date/times and get 4 > hours as the result. > Please help mm = two-digit month, not minutes. nn = minutes. Why 12, though? Because the > > ?format(#2/2/2006 2:35:00 PM# -#2/2/2006 10:35:00 AM#,"[h]:mm") > :12 result of #2/2/2006 2:35:00 PM# - #2/2/2006 10:35:00 AM# is, numerically, 0.166666666671517, and since the integer portion of this number (which represents the date) is 0, that equates to 1899-12-30, hence the month of 12. Thanks for the explanation, how do I get the result (4:00) that I want
though. I tried using nn and get 0 Show quoteHide quote "Jeff Johnson [MVP: VB]" wrote: > > "Paulymon" <Pauly***@discussions.microsoft.com> wrote in message > news:EC777025-45BC-44CB-9BEE-BD6888DB26BF@microsoft.com... > > >I entered the following in my immediate window and expected to see a result > >of > > 4:00 > > > > Why is it showing me :12 ? I want to subtract the 2 date/times and get 4 > > hours as the result. > > Then use DateDiff(). > > > Please help > > > > ?format(#2/2/2006 2:35:00 PM# -#2/2/2006 10:35:00 AM#,"[h]:mm") > > :12 > > mm = two-digit month, not minutes. nn = minutes. Why 12, though? Because the > result of #2/2/2006 2:35:00 PM# - #2/2/2006 10:35:00 AM# is, numerically, > 0.166666666671517, and since the integer portion of this number (which > represents the date) is 0, that equates to 1899-12-30, hence the month of > 12. > > > Paulymon wrote:
> Thanks for the explanation, how do I get the result (4:00) that I want ?format$(#2/2/2006 2:35:00 PM# - #2/2/2006 10:35:00 AM#, "h:nn")> though. I tried using nn and get 0 Paulymon wrote:
> Thanks for the explanation, how do I get the result (4:00) that I want ?format(#2/2/2006 2:35:00 PM# -#2/2/2006 10:35:00 AM#,"h:nn")> though. I tried using nn and get 0 > Thanks for the explanation, how do I get the result (4:00) that I want Convert your subtraction to a date so VB knows what it is...> though. I tried using nn and get 0 Format(CDate(#2/2/2006 2:35:00 PM# - #2/2/2006 10:35:00 AM#), "hh:nn") Of course, in a real program, those two dates would be stored in Date variables and their subtraction would be stored in a Date variable and that last Date variable would be used as the first argument. Rick
Show quote
Hide quote
"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net> ......and might even use the built in DateDiff function to do the math <g>wrote in message news:eD4GhwDKGHA.3728@tk2msftngp13.phx.gbl... >> Thanks for the explanation, how do I get the result (4:00) that I want >> though. I tried using nn and get 0 > > Convert your subtraction to a date so VB knows what it is... > > Format(CDate(#2/2/2006 2:35:00 PM# - #2/2/2006 10:35:00 AM#), "hh:nn") > > Of course, in a real program, those two dates would be stored in Date > variables and their subtraction would be stored in a Date variable and > that > last Date variable would be used as the first argument. > > Rick -- Ken Halter - MS-MVP-VB - Please keep all discussions in the groups.. DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
Show quote
Hide quote
> >> Thanks for the explanation, how do I get the result (4:00) that I want But that won't give him both the hours and minutes directly... he would have> >> though. I tried using nn and get 0 > > > > Convert your subtraction to a date so VB knows what it is... > > > > Format(CDate(#2/2/2006 2:35:00 PM# - #2/2/2006 10:35:00 AM#), "hh:nn") > > > > Of course, in a real program, those two dates would be stored in Date > > variables and their subtraction would be stored in a Date variable and > > that > > last Date variable would be used as the first argument. > > > > Rick > > .....and might even use the built in DateDiff function to do the math <g> do DateDiff for minutes and then calculate the hours and remainder minutes. No big deal, of course, but I sensed the OP was looking to do it "all in one". Rick
KeyPress event help needed
module Best way to extract a word from a sentence Thesaurus & internationalisation Does this serial port device exist? Text box - Change/Lost Focus use VB6 Intercepting Ctrl+Alt+Del Installing VB5 Application Causing Hardware Problems? color format Outlook Style Date Grouping |
|||||||||||||||||||||||