display date

Hi,

I would like to create a unique number as follows:

the date today is 24-08-05 en there are 5 messages sent to our system.

For each of the messages are unique numbers available from which one can get the date out:

example:

050824-001
050824-002
050824-003
050824-004
050824-005

Tomorrow there will be 2 messages:

050825-001
050825-002

So the numbers after the date must increment and after each day, the date must be changed to the appropriate date.

How to code this?
 

jongpau

Member
Why not put the two parts in two separate fields and slam an index on it. That way you can use find-last etc with today's date. It's easy enough to concatenate the two fields into a single string for display purposes...
 

wollu

New Member
And what happens, if you have more then 999 messages a day? This kind of enumeration seems a bit odd to me. Why not just sequence the table straight from 1-n? Stash time info somewhere else. Also will the correct enumeration rely on your computers watch. Having your own sequence number is less dependant on things outside your program. Anyway. You asked for it...

Code example (somewhat dirty) :

DEFINE VARIABLE myEnum AS INTEGER NO-UNDO.

/* I wouldn't try this at home. The handling of the table is quite
risky, but the point is how to generate the number
in a reliable way. So no date format differences would be a problem */

FIND LAST sometable WHERE ENTRY(1,sometable.myEnum,"-") EQ SUBSTITUTE("&1&2&3-&4",
YEAR(TODAY),
STRING(MONTH(TODAY),"99"),
STRING(DAY(TODAY),"99") NO-LOCK USE-INDEX myEnum. /* Jesus! I wouldn't want to try this with huge datasets */

IF AVAILABLE sometable
THEN ASSIGN lastNum = INT(ENTRY(2,sometable.myEnum,"-")) + 1.
ELSE ASSIGN lastNum = 1.

ASSIGN myEnum = SUBSTITUTE("&1&2&3-&4",
YEAR(TODAY),
STRING(MONTH(TODAY),"99"),
STRING(DAY(TODAY),"99"),
STRING(lastNum,"999").

/* Do whatever you need after that */

This example shows, how complicated it is to handle such enumartions. You can not use friendly find-statements and - even worse - the integrity of your data will rely on code, not on numbers. Yak!
 
Table - MyTable
Fields - DateRaised (DATE), DateSeq(CHAR), ...
Index - DateRaised (ASCENDING)

Sequence - MyTableSeq

Code:
IF NOT CAN-FIND(FIRST MyTable
  WHERE DateRaised EQ TODAY) THEN 
  ASSIGN CURRENT-VALUE(MyTableSeq) = 0.
CREATE MyTable.
ASSIGN MyTable.DateRaised = TODAY
       MyTable.DateSeq = SUBSTITUTE("&1&2&3-&4",
                         STRING(YEAR(TODAY,"99")),
                         STRING(MONTH(TODAY,"99")),
                         STRING(DAY(TODAY,"99")),
                         STRING(NEXT-VALUE(MyTableSeq),"999"))
       ...
 
Top