Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Easy way to convert datetime() to the nearest hour?
Message
From
12/01/2006 18:45:09
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01086260
Message ID:
01086383
Views:
49
>>>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.
Previous
Reply
Map
View

Click here to load this message in the networking platform