Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Date for a Field

Status
Not open for further replies.

kafka

Programmer
Oct 17, 2000
27
US
Can anyone explain how to specify a date format for a particular field. For one field I need to set the date format to accept dd/mm/yyyy which is a combination of the European + long date format. For another field I need only mm/yyyy.

Thanks ahead of time,


kafka
 
Kafka, you cannot control how the dates are stored, only how they are displayed.

You can use the various SET DATE commands in VFP, or you can "roll your own" by using DTOS(mydate) and parsing it. DTOS() always returns the date in YYYYMMDD format, regardless of any other settings. So, you could do this:

select MyField1, substr(dtos(MyDate), 4, 2) + "/" + ;
[tab]substr(dtos(MyDate), 6, 2) as MyFormattedDate ;
[tab]from MyTable


Robert Bradley

 
Thanks Robert,

I am aware of the Set Date command and have looked it up using the Help library, however I still don't quite know where and how to use the set date command. Could you provide a brief example?

Could I use your example to display a date is just the mm/yyyy format as well?
 
To get the program to accept a date of dd/mm/yyyy then you should

SET DATE BRITISH
SET CENTURY ON

before you ask the user for the input. Most developers (I think) apply these settings at the start of their main program as they are configuring the environment.

If your program needs to have the date in a different format by default, then I suggest you store the current state of DATE and CENTURY to variables which you can reapply after you have finished with the BRITISH format.
Code:
SET DATE AMERICAN    && MM/DD/YYYY
SET CENTURY OFF      
dMyDate = date()     && 10/26/00

<code>

procedure GetEuroDate
*-- Example procedure to get a European date.
local cDateFormat, cCenturyFormat

cDateFormat = set('date')          && &quot;American&quot;
cCenturyFormat = set('century')    && &quot;OFF&quot;

SET DATE BRITISH    && 26/10/00
SET CENTURY ON      && 26/10/2000

<code to get European date>

SET DATE &cDateFormat.            && &quot;American&quot;
SET CENTURY &cCenturyFormat.      && &quot;OFF&quot;

return



To show a date as mm/yyyy. You can show it as a character string (I don't know if VFP will allow you to use a partial date format).

dMyDate = date()                            && 26/10/2000
cMyMthYr = month(dMyDate)+&quot;/&quot;+year(dMyDate) && &quot;10/2000&quot;

I haven't tried the above, this is working from memory - which is failing some times :))


 
Seems like it would be easier to store the info in the database as a character string and use the CTOD() or date(yy,mm,dd) function when you need to compute values.


David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top