Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

HOUR(), MINUTE(), SEC()

These functions extract the hour, minute and second portions of a datetime value. Backward compatibility with previously existing functions makes for some funny, non-intuitive abbreviation rules.

Usage

nHours = HOUR( tDateTime )
nMinute = MINUTE( tDateTime )
nSeconds = SEC( tDateTime )

HOUR() always returns the number of hours since midnight, regardless of the setting of SET HOUR. MINUTE() returns a numeric value from 0 to 59. No surprises here. MINUTE() may be abbreviated as short as Minu(), but realize that MIN() is the Minimum function, something completely different. Though confusing, it fits the general rule that you can abbreviate commands and functions to four characters or more. SEC() returns a numeric value from 0 to 59. In the opposite logic to MINUTE(), SEC() must be just the three characters—anything from Seco() up to SECONDS() causes Visual FoxPro to return the number of seconds since midnight, or squawk if a parameter is passed.

Example

? "The time is now " + LTRIM(STR(HOUR(DATETIME()))) + ;
  " hours, " + LTRIM(STR(MINUTE(DATETIME()))) + ;
  " minutes and "  + LTRIM(STR(MINUTE(DATETIME()))) + ;
  " seconds past midnight"

See Also

Date(), DateTime(), Min(), Seconds(), Set Hour