Any idea how to pad a single digit number embedded in a string with leading zeroes if you want to see a 2 digit value?
I'm outputting a date value in this format: mm/dd/yyyy and I'd like to see
09/05/1859
as opposed to the default which is
9/5/1859
Thanks in advance!!
Pad a number?
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Re: Pad a number?
If you've got month, day and year as separate variables, I know it could be done with strformat(). I'm not aware of any functions that deal specifically with dates, but they may exist.
https://wiki.rptools.info/index.php/strformat
https://wiki.rptools.info/index.php/strformat
Re: Pad a number?
I don't think the wiki makes it very intuitive on how to use, so here's an example.
Code: Select all
[H: date = substring(json.get(getInfo("client"),"timeDate"),0,10)]
[H: year = listGet(date,0,"-")]
[H: month = listGet(date,1,"-")]
[H: day = listGet(date,2,"-")]
<!-- no leading 0s, direct variable name method -->
[R: strformat("%{month}-%{day}-%{year}")]<br>
<!-- leading 0s, substitution method -->
[R: strformat("%02d/%02d/%s",month,day,year)]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
-
- Cave Troll
- Posts: 74
- Joined: Sat Aug 17, 2019 3:49 pm
Re: Pad a number?
Thanks very much !!