Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Easy way to convert datetime() to the nearest hour?
Message
De
12/01/2006 18:45:09
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01086260
Message ID:
01086383
Vues:
50
>>>How can I convert datetime() to the nearest hour?
>>
>>Try:
>>
>>lnHour = ROUND(HOUR(DATETIME()) + MINUTE(DATETIME()),0)
>
>I figured this out:
>
ltTimeToReschedule = DATETIME() 	
	lnMinutes = MINUTE(m.ltTimeToReschedule)
	lnMinutes = lnMinutes - FLOOR(MINUTE(m.ltTimeToReschedule)/15)*15	
	lnSeconds = SEC(m.ltTimeToReschedule)
	ltTimeToReschedule = m.ltTimeToReschedule + (15-m.lnMinutes) * 60 - m.lnSeconds
=MESSAGEBOX(m.ltTimeToReschedule)
It should have been:

lnHour = ROUND(HOUR(DATETIME()) + MINUTE(DATETIME())/60 + SEC(DATETIME())/3600,0)

To account for the minutes are 60 per hour (minutes divided by 60). The above returns hour in 'military', i.e., 6pm is 18. This returns the closes hour to the datetime value.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform