PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: FormatNumber()[Next]: GenerateFileName()
\ -> Rexx -> Inbuilt PPWIZARD Functions -> FormatTime()

FormatTime()

This is an inbuilt function function provided by PPWIZARD.

The purpose of this routine is to format a time stamp (such as that returned by TimeStamp() or GetFileTimeStamp()) into a "pretty" text format. It can be configured to support any language and you can also configure how a date and time look by default.

The return code is the formatted value. If you can't work out what is happening turn debug on.

This routine takes parameters as follows:

  1. FormatSpec
    This is a string which contains codes which will get replaced by date/time information (more detail below). If not supplied a default format is used, the default can be modified with the "*_DEFAULT_TIME_FORMAT" (see below about configuration).

  2. TimeStamp
    This is a timestamp of the form "YYYYMMDDHHMMSS". If not supplied the current date and time is used.

  3. ConfigSet
    This can be used to configure this routine, the default value is "FORMATTIME" (more detail below).

FormatSpec

This is a string which may contain two character long control codes (all of which begin with "%"), if the control code is not recognised then it is ignored.

In the following examples are shown in red (based on the current time (Sun Nov 5 2017 at 10:00:23am), available codes are:

ConfigSet

You can configure the text used for the day or month names (to support other languages such as German) or alter the format of some of the codes.

You do this by defining certain macros, the "ConfigSet" parameter is the prefix for a set of these variables. The idea is that this makes it easy for you to define multiple languages and/or formats and switch between them easily.

The configuration macros are (* replaced by "ConfigSet" value):

Example #1

This is a sample of a macro which will return the date/time of a file in the format you specify:

;--- Create macro to get a file date/time in FormatTime() format ---
#NextId                ;;Make sure temp variables will not clash...
#( ''
   #define GetFileDateTime

   ;--- The date/time of file is "input", so make sure PPWIZARD knows ---
   #DependsOn INPUT        "{$File}"

   ;--- Work out date/time in required format ---
   #evaluate  @@TmpDateTime  ^FormatTime("{$Fmt=^%v^}", GetFileTimeStamp("{$File}", "D"))^

   ;--- Generate the generated time ---
   <$@@TmpDateTime>

   ;--- No longer need the definition ---
   #undef @@TmpDateTime
#)

;--- Try the macro ---
File date      is <$GetFileDateTime File="<?InputComponent>">
File date/time is <$GetFileDateTime File="<?InputComponent>" Fmt="%c">
File time      is <$GetFileDateTime File="<?InputComponent>" Fmt="%X">

Example #2

This is some test code, apart from anything else it works/demonstrates each format:

;--- Get date/time of a specific file ---
#DefineRexx ''
   @@File = "1.in"
   @@Ts = GetFileTimeStamp(@@File)
   if  @@Ts = -1 then
       ToFile = 'The file "' || @@File || '" does not exist!'
   else
   do
       @@Formatted = FormatTime("%c", @@Ts);
       ToFile = 'The file "' || @@File || '" is dated ' || @@Formatted
   end;
#DefineRexx
=======================
<??ToFile>
=======================


;--- Test Each code ---
;#define FORMATTIME_TIME_FORMAT %I:%Mp
#NextId
#DefineRexx 'TestCode'
       @@Codes  = '{$#1}';
       @@Result = FormatTime(@@Codes)
       @@Show   = 'The code "' || @@Codes || '" was replaced with "' || @@Result || '"'
       call say @@Show
       ToFile = ToFile || @@Show || '<' || '?NewLine>'
#DefineRexx
#DefineRexx ''
   ToFile = '';
   <$TestCode "%%">
   <$TestCode "%a">
   <$TestCode "%A">
   <$TestCode "%b">
   <$TestCode "%B">
   <$TestCode "%d">
   <$TestCode "%e">
   <$TestCode "%#">
   <$TestCode "%H">
   <$TestCode "%!">
   <$TestCode "%I">
   <$TestCode "%@">
   <$TestCode "%j">
   <$TestCode "%$">
   <$TestCode "%m">
   <$TestCode "%M">
   <$TestCode "%p">
   <$TestCode "%S">
   <$TestCode "%y">
   <$TestCode "%Y">
   <$TestCode "%c">
   <$TestCode "%x">
   <$TestCode "%X">
   <$TestCode "%D">
   <$TestCode "%r">
   <$TestCode "%R">
   <$TestCode "%T">
   <$TestCode "%v">
   <$TestCode "%Z">
   ToFile = ToFile || d2c(10)
#DefineRexx
<?NewLine>
<?NewLine>
=======================
<??ToFile>
=======================

Example #3 - Modify Output Format

;--- Show the default ---
#DefineRexx ''
       WantLongMonth = "%B";
       call say "MONTH = " || FormatTime(WantLongMonth);
#DefineRexx

;--- Change the DEFAULT output for month names (and define a second non-default) ---
#define FORMATTIME_MONTH_NAMES_LONG aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll
#define      MYFMT_MONTH_NAMES_LONG #aa #bb #cc #dd #ee #ff #gg #hh #ii #jj #kk #ll

;--- Try the changes out ---
#DefineRexx ''
       WantLongMonth = "%B";
       call say "MONTH = " || FormatTime(WantLongMonth);
       call say "MONTH = " || FormatTime(WantLongMonth,,"MYFMT");
#DefineRexx


email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: FormatNumber()[Next]: GenerateFileName()


PPWIZARD Manual
My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am