How to Manipulate DateTime Fields in a Browse

Last reviewed: April 30, 1996
Article ID: Q130346
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SUMMARY

Microsoft Visual FoxPro introduces a new data type, DateTime, that allows a date and time value to be stored in a single field. By default, Visual FoxPro displays the data stored to DateTime fields in a MM/DD/YY HH:MM:SS XM format. This article describes how to display just the date or just the time portion of a DateTime field in a Browse window.

MORE INFORMATION

Visual FoxPro does not offer a command or function that automatically retrieves just the Date or just the Time portion of a DateTime field. The code provided below creates two functions GETDATE() and GETTIME(). The BROWSE command will use those functions to display just the date and just the time of a Datetime field.

Code Sample

* * Begin Program * * This program assumes a table already exists with a DateTime field named * tField. *

BROWSE FIELDS date=getdate(tField), time=gettime(tField)

* * The BROWSE command passes tField to the functions getdate() * and gettime(). Each function returns to the BROWSE the values of * justdate and justtime. *

FUNCTION getdate PARAMETERS tField justdate = SUBSTR(TTOC(tField),1,8) RETURN justdate ENDFUNC

FUNCTION gettime PARAMETERS tField justtime = SUBSTR(TTOC(tField),10) RETURN justtime ENDFUNC

* NOTE: The justdate and justtime fields will be read-only at run time. * * End Program *


Additional reference words: 3.00 VFoxWin
KBCategory: kbprg kbcode
KBSubcategory: FxprgTable


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.