Trying to create a number based on a formula

Hi there!

I am wanting to create a 16 digit number such as the following:

2003091412563214

The number is made up as follows:

2003 = Year

09 = Month

14 = Day

12 = Hour

56 = Minute

32 = second

14 = Characters in a name.

The script I have wrtten is as follows:

aa := @If(@Text(@Month(@Now))>=@Text(9); “0”+@Text(@Month(@Now)) ; @Text(@Month(@Now)));

bb := @If(@Text(@Day(@Now))>=@Text(9); “0”+@Text(@Day(@Now)) ; @Text(@Day(@Now)));

cc := @If(@Text(@Hour(@Now))>=@Text(9); “0”+@Text(@Hour(@Now)) ; @Text(@Hour(@Now)));

dd := @If(@Text(@Minute(@Now))>=@Text(9); “0”+@Text(@Minute(@Now)) ; @Text(@Minute(@Now)));

ee := @If(@Text(@Second(@Now))>=@Text(9); @Text(“0”)+@Text(@Second(@Now)) ; @Text(@Second(@Now)));

ff := @If(@Text(@Length(@Name([CN];@UserName)))>=@Text(9);“0”+@Text(@Length(@Name([CN];@UserName)));@Text(@Length(@Name([CN];@UserName))));

@Text(@Year(@Now))+aa+bb+cc+dd+ee+ff

I have written the formula in such a way that if there the result is a single digit, a 0 will be placed in front of it. For example, 1 will become 01. This will the be added to the final string.

However, this is not working correctly. The number 0 is correclt appended to aa but not to any of the others. Can anyone share some light on this?

I hope that it makes sense.

Regards

Vaughan Rivett

Subject: Trying to create a number based on a formula

Here is a formula that I am using on a form to create field value based on the date and time:

REM {$DtTm is a Date Time field in the format of mm/dd/yyyy hh:mm:ss AM(PM)};

REM {We need to convert this to a string YYYYMMDDHHMMSS and if PM };

REM { we need to add 12 to the HH number};

FIELD txtYear := @Text( @Year( $DtTm ) );

FIELD txtMon := @If( @Month( $DtTm ) > 9 ; @Text( @Month( $DtTm ) ); “0” + @Text( @Month( $DtTm ) ) );

FIELD txtDay := @If( @Day( $DtTm ) > 9 ; @Text( @Day( $DtTm ) ); “0” + @Text( @Day( $DtTm ) ) );

FIELD txtHour := @If( @Hour( $DtTm ) < 10 & @Right(@Text($DtTm) ; 2 ) = “AM” ; “0” + @Text( @Hour( $DtTm ) ); @Text( @Hour( $DtTm ) ) );

FIELD txtMin := @If( @Minute ( $DtTm ) > 9 ; @Text( @Minute( $DtTm ) ); “0” + @Text( @Minute( $DtTm ) ) );

FIELD txtSec := @If( @Second( $DtTm ) > 9 ; @Text( @Second( $DtTm ) ); “0” + @Text( @Second( $DtTm ) ) );

txtYear + txtMon + txtDay + txtHour + txtMin + txtSec ;

Hope it helps

Dennis

Subject: RE: Trying to create a number based on a formula

It’s not always going to work for the month either – it depends which month you test it during.

When you use >= to compare two text values, such as @Text(@Day(@Now)) and @Text(9), they are compared in alphabetical order. 13 > 9 but “13” < “9”.

To add leading zeroes, use @Right, e.g. @Right(“0” + @Text(@Day(@Now)); 2).

Subject: RE: Trying to create a number based on a formula

Andre,

Thanks for your response. I made the changes and found that it works well.

However, sometimes it doesn’t work. Any thoughts on this.

Also, if the seconds are “00” they appear as “0”. This number seems to act slightly different to the others.

Any ideas?

Subject: RE: Trying to create a number based on a formula

Andre,

The following code seems to fix the problem with the “0” and seems to be reliable.

aa := @If(@Text(@Month(@Now))>@Text(10); @Right(“0”+@Text(@Month(@Now));2) ; @Text(@Month(@Now)));

bb := @If(@Text(@Day(@Now))>@Text(10); @Right(“0”+@Text(@Day(@Now));2) ; @Text(@Day(@Now)));

cc := @If(@Text(@Hour(@Now))>@Text(10); @Right(“0”+@Text(@Hour(@Now));2) ;@Text(@Hour(@Now))=“0”;@Right(“00”;2); @Text(@Hour(@Now)));

dd := @If(@Text(@Minute(@Now))>@Text(10); @Right(“0”+@Text(@Minute(@Now));2) ;@Text(@Minute(@Now))=“0”; @Right(“00”;2); @Text(@Minute(@Now)));

ee := @If(@Text(@Second(@Now))>@Text(10); @Right(“0”+@Text(@Second(@Now));2);@Text(@Second(@Now))=“0”; @Right(“00”;2); @Text(@Second(@Now)));

ff := @If(@Text(@Length(@Name([CN];@UserName)))>@Text(10);@Right(“0”+@Text(@Length(@Name([CN];@UserName)));2);@Text(@Length(@Name([CN];@UserName))));

@Right(@Text(@Year(@Now));2)+aa+bb+cc+dd+ee+ff

Thanks for your help.

Regards

Vaughan

Subject: RE: Trying to create a number based on a formula

aa := @Right(“0”+@Text(@Month(@Now));2) ;bb := @Right(“0”+@Text(@Day(@Now));2) ;

cc := @Right(“0”+@Text(@Hour(@Now));2) ;

dd := @Right(“0”+@Text(@Minute(@Now));2) ;

ee := @Right(“0”+@Text(@Second(@Now));2);

ff := @Right(“0”+@Text(@Length(@Name([CN];@UserName)));2);

@Right(@Text(@Year(@Now));2)+aa+bb+cc+dd+ee+ff