--------------------------------------------------------------------------- M i n e r v a S o f t w a r e T e c h n i c a l R e l e a s e Number: 017/Dates Baring Crescent Date: 24/09/92 Exeter Author: MK Devon Pages: 02 EX1 1TL Using dates in MultiStore and FlexiFile ----------------------------------------------------------------------------- Many applications require a MultiStore or FlexiFile file to be sorted into date order. There are two ways to do this, depending on the type of application. If the application only needs the file in strictly the correct order on some occasions (eg for an occasional report), the solution is simple. If the application requires the file to be in date order at all times, the solution is slightly more complicated. Occasional Sorting ~~~~~~~~~~~~~~~~~~ For applications requiring only occasional sorting, the date may be kept in a string field which is long enough to accept dates in the format you would prefer to type them in (it does not matter what this is). The dates should be entered into the field as records are added or edited. If this field is called 'date' (for example), the file may be sorted by simply entering the following sort expression: FNreaddate(@date) This is a function which converts a string date (in any reasonable format) into an integer representing the number of days since the theoretical birth of christ, according to the Julian system. The result will be used to sort the file. Permanent Sorting ~~~~~~~~~~~~~~~~~ Permanent sorting requires an index to be created and unfortunately indices cannot access BASIC functions such as FNreaddate(). The indexed field must therefore contain the date in a meaningful format for the index mechanism, ie with the most significant digits first. This means the dates need to be entered in a consistent format in the order year, month, day. Thus the 2nd of July 1979 might be entered as: 19790702 or 790702 or 1979/07/02 or 79/07/02 etc one of these formats must be chosen and stuck to throughout the file. The field used should be a string field of the correct length and constructing an index on this field will keep the file in date order. --01---017/Dates----------------------------------------------------------- --02---017/Dates----------------------------------------------------------- To simplify matters, the date can be kept in two fields if there is enough space. In this case, the first field is free format (as in Occasional Sorting, above) and the second field is in fixed format and is used for the index. The second, fixed format field is generated automatically by a macro. Suppose the free format field is called 'date' and the fixed format one is called 'dkey.' A macro needs to be set up containing these lines: d%=FNreaddate(@Date):a$=RIGHT$(STR$(FNnyear(d%)),2) @dkey=a$+RIGHT$("0"+STR$(FNnmon(d%)),2)+RIGHT$("0"+STR$(FNnday(d%)),2) The 'Edit Mode' option should then be turned on in the Macro menu. The 'dkey' field will then be updated whenever the 'date' field changes, keeping the index up to date. Note that the above example allows only two digits for the year. If you are using dates outside this century, you will need to change the 2 at the end of the first line to a 4 and use an 8 character field rather than a 6 character field. Reporting ~~~~~~~~~ If you have used a free format date field you may wish to force dates to be consistent on reports. This can be done using the FNstrdate1() function in formula and paged reports. The expresion to use is: FNstrdate1(FNreaddate(@date),3) Note that the value 3, at the end, is a format number and you may wish to change this for your application. --02---017/Dates-----------------------------------------------------------