Convert Date to a code
I need to convert date(dd/mm/yy) to a 2 character code(example "1A") where first character("1") represents the month(mm) and 2nd char("A") represents the year(yy), and we can ignore date(dd). I have pre-defined values for each month and each year so it will change for every month like below.
example:
21/01/24 -> 1A
21/02/24 -> 2A
.
.
.
.
21/01/25 -> 1B
21/02/25 -> 2B
what is the best way for me to implement this? I wanted to get a direction first before i can get started on this.
-
Peter Thane
★ BarTender Hero ★
You could add your year codes into an Array and then reference them from there.
Something like this would do the job for you:
Dim YearCode
YearCode = Array("A","B","C","D","E","F","G","H","I","J","K")Value = "1A"
Value1 = Month(Format.NamedSubStrings("TheDate").Value)
Value2 = Format.NamedSubStrings("TheDate").Value
Value2 = Right(Value2,1)
Value2 = YearCode(Value2)
Value = Value1 & Value2NOTE: for this I have added a Date field onto my label and made it a Named Data Source which the month and year VB are getting the base date from. You will need to change the array to match the values you want for each year.
I created my VB as a Multi Line script but if your date comes from a Database or a Data Entry form entry then you would probably be better making this an Event Controlled Script that is processed after the base data is populated on the label (eg OnNewRecord for a database or OnPostPrompt for data entry values)
0
Vous devez vous connecter pour laisser un commentaire.
Commentaires
1 commentaire