Manage Learn to apply best practices and optimize your operations.

Military Time

Insanely complicated input translation formula for a text field which converts
'12 hour clock' time to military time. You enter 2:10 pm, you get 14:10. The
cool part is that it leaves times that are properly entered in military time
format alone! Useful when a service technician, for example, must enter the
time something happened while on the phone with a customer. The field name I
used is accident_time. Warning: If you have a weak stomach, do not read this
REM "Convert to military time";
REM "Hours always required, minutes are optional";
REM "Follow time with a letter A or a letter P, case not important";
REM "Colon is used if present, but it is optional";
entry := @UpperCase(@Trim(accident_time));
lenEntry := @Length(entry ) ;
ampm := @If( @Contains(entry;"A" );"am";@Contains(entry;"P" );"pm";"?" );
colon := @If( @Contains(entry;":" );"Y";"N");

padEntry :=
If(lenEntry=3;"0"+Entry;Entry ) ) );Entry ) ;
justtime := @Trim( @If( ampm = "?";Padentry;@If(ampm="am";@Left(Padentry;"A"
);@Left(Padentry;"P" ) ) ) ) ;
lenTime := @Length(justtime) ;
hours :=@If(colon="Y";@Left(justtime;":"
);@If(lenTime=4;@Left(justtime;2);@If(lenTime=3;@Left(justtime;1);justtime ) )
) ;
lenHours := @Length(hours ) ;
tempmins := @If(colon="Y";@Right(justtime;":"
valhours := @TextToNumber(hours ) ;

mins := @If(@Matches(tempmins;"+{A-Z}" )&tempmins!="";"00";tempmins ) ;
hoursmins := @Text( valhours+ @If(ampm="pm" & valhours < 12;12;0 ) -
@If(ampm="am" & valhours = 12;12;0 )) + @If(mins="";"00";mins) ;
REM "String is never longer then four characters, so eliminate any junk at end";
military := @Left( @If(@Length(hoursmins)=3;"0";"") + hoursmins;4);
________ Validation Formula ______
RealNumber := @If(@IsNumber(@TextToNumber( accident_time)) ;"Y";"N" ) ;
numberTime :=@TextToNumber(accident_time );
justMinutes := @Modulo(numberTime;100) ;
@If(accident_time="";@Failure("The accident time is
required");accident_time="@ERR"|RealNumber = "N";@Failure("The accident time
you entered cannot be converted to military time");NumberTime>2399 ;
@Failure("The highest accident time you can enter is 23:59 or 11:59
pm");justMinutes > 59 ; @Failure("The accident time minutes cannot exceed
59"); @Matches(accident_time;"+{A-Z}" ); @Failure("Invalid Entry");@Success)

Dig Deeper on Domino Resources

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...