Reputation: 271
I have a computed field that serves as "reference number" by combining date and time. But, the problem is the time format, it displays AM/PM, I need to make it as military time format or 24hr format. Is there a formula for that? I've search some notes book but can't find any. Can you help me? Here's my code:
REM {Variable Assignment};
cType := RequestType;
cDate := @Text(@Created; "D0S0");
cTime := @Text(@Now; "T0S1");
REM {Get the list of synonyms from the svType view};
cView := "svKeywordType";
clist := @DbColumn("": ""; @DbName; cView; 2);
@If((@IsError(clist) | clist = ""); "There is no request type in this system."; clist);
REM {Get the request type description list};
cDesclist := @Left(clist; " | ");
REM {Get the request type synonym list};
cSynonymlist := @Right(clist; " | ");
REM {Check the position of the request type from the list};
cPos := @Member(cType; cDesclist);
REM {Given the position, get the request type description};
cSynonym := @Subset(@Subset(cSynonymlist; cPos); -1);
REM {Get the mm value};
cMonth := @Left(cDate; "/");
REM {Get the dd value};
cDay := @Left(@Right(cDate; "/"); "/");
REM {Get the yyyy value};
cYear := @Right(@Right(cDate; "/"); "/");
cHour := @Left(cTime; ":");
cMinute := @Left(@Right(cTime; ":"); ":");
cSecond := @Right(@Right(cTime; ":"); ":");
cdateToday := @Text(@Today; "D0S0");
ctimeToday := @Text(@Now; "T0S1");
cRef := cSynonym + "-" + cMonth + cDay + cYear + "-" + cHour + cMinute + cSecond;
@If(cType = "" | @IsError(cSynonym); ""; cRef)
Edit: By the way, the field that I'm using is text. Tried using calendar and set to 24 hour format but didn't work.
Upvotes: 1
Views: 4208
Reputation: 30960
Use @Hour
- hours are represented as 0 through 23 for 12 AM through 11 PM.
Code for a two digit hour string:
cHour := @Right("0" + @Text(@Hour(@Now)); 2);
Your formula will work only for English/American time/data string conversion. It wouldn't work for German e.g.
Better you use other @Functions too: @Year, @Month, @Day, @Minute, @Second
:
REM {Get the mm value};
cMonth := @Right("0" + @Text(@Month(@Created)); 2);
REM {Get the dd value};
cDay := @Right("0" + @Text(@Day(@Created)); 2);
REM {Get the yyyy value};
cYear := @Text(@Year(@Created));
cHour := @Right("0" + @Text(@Hour(@Now)); 2);
cMinute := @Right("0" + @Text(@Minute(@Now)); 2);
cSecond := @Right("0" + @Text(@Second(@Now)); 2);
Upvotes: 4