Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Math with dates/times ----- Novice
Message
De
02/04/1998 10:16:29
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
02/04/1998 08:16:07
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00088775
Message ID:
00088944
Vues:
33
>>>>>Is there a convenient way to do arithmetic with dates and times in
>>>>>VFP? To be specific, I am continually updating data in a grid and
>>>>>would like to notify the user of the time of the *next* update (say,
>>>>>15 minutes after the previous one).
>>>
>>>Now Ed! He wants to do math and he did say he is a novice.
>>>
>>>Paul try this:
>>>
>>>[The next update will occur at ]+subst(time(),1,3)+alltrim(str(val(subst(time(),4,2))+15))
>>>
>>>To get this:
>>>
>>>The next update will occur at 16:50
>>>
>>>DJ :o)
>>
>>Donald,
>>That won't work because at 16:50, if you use the above command, the next update will occur at 16:05. I think the solution would be a bit more complex than that.
>
>I agree (and was surprised to discover this). I don't understand the idea
>behind coming up with the DateTime data type since it really doesn't convey
>any advantages over having Date/Time as a character data type. You have this special data type that does nothing (really). I thought maybe I was missing
>something or perhaps that there was a commonly known procedure for performing
>calculations on time.
Paul,
Actually datetime data type is perfect for datetime arithmetic and does many things (ie: in one of my apps, identify the starttime, endtimes and I could easily say how long it took to do a process just by doing simple arithmetic. Or another to build up a timesheet). For your case a detailed, step by step explanation below :
* myDateTimeField is the datetime field that we'll perform arithmetic on
* For this example suppose code is in Valid of myDateTimeField textbox
* this.value would represent the current datetime value
* We need 15 mins later
nMinutes = 15
dtNextCheckTime = this.value+nMinutes*60
* We added 15 mins (15*60seconds) to current datetime value in field
* and dtNextCheckTime is in datetime format
cNextCheckTime = ttoc(dtNextCheckTime) && Converted to character
* Now something like "01/01/1998 15:23:21"
wait window nowait ;
  "Next check is on "+cNextCheckTime
* Or just to show hour,min
cTimeMessage = substr(cNextCheckTime,12,5)
wait window nowait ;
  "Next check is on "+cTimeMessage
* We didn't touch how hour or date would be displayed
* assuming already in format user wants 
* To change them you would use "set date to ...", "set hours to .."
* Below doing all above in one line :
* wait window nowait ;
*  "Next check is on "+ttoc(this.value+nMinutes*60)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform