TOPIC: Leading zero on time values

Leading zero on time values 27 Oct 2015 12:23 #2050

  • RonMoses
  • RonMoses's Avatar
  • Offline
This has been discussed elsewhere, but I don't believe there was a conclusive resolution. I don't see a way to include a leading zero in time values in a filename. You can't use the Current Time variable because of filename restrictions. If you use Current Hour and Current Minute, you don't get a leading zero. So 8:00am comes out as 80 instead of 0800. Using a Right() function fails because of the comma.

Got a solution for this, Logicity folks?
The administrator has disabled public write access.

Leading zero on time values 27 Oct 2015 17:34 #2059

  • aellis
  • aellis's Avatar
  • Offline
Ron, have you tried JoelM's technique listed at the bottom of this thread?

www.logicitysuite.com/forum/tips-tricks/...ables-reference.html

I think you'd just swap out where he was doing year (yyyy) month (m) and day (d) for hour (H) and minute (N).
The administrator has disabled public write access.
The following user(s) said Thank You: RonMoses

Leading zero on time values 27 Oct 2015 17:42 #2060

  • RonMoses
  • RonMoses's Avatar
  • Offline
Well dagnabbit.

I actually did try it, but for whatever reason I used "&" instead of "+" to concatenate. And of course we know that's a no-no. So I screwed that up. Fixed now. Thanks!
The administrator has disabled public write access.

Leading zero on time values 28 Oct 2015 17:11 #2065

  • RonMoses
  • RonMoses's Avatar
  • Offline
Except it doesn't appear to have worked. Here's the end of my filename string:

%{Right("0" + DatePart("h",Now()), 2)}%%{Right("0" + DatePart("n",Now()), 2)}%.pdf

At 8:00am, that should have given me 0800.pdf, but it gave me 80.pdf. Same thing happened at 1:00pm, I got 130.pdf. So why is this wrong?
The administrator has disabled public write access.

Leading zero on time values 28 Oct 2015 17:21 #2066

  • RonMoses
  • RonMoses's Avatar
  • Offline
It occurs to me I might be dealing with an implicit type conversion problem. I'm guessing DatePart() returns an int, and I'm guessing int is a higher order of precedence than string in VBScript. In that case, the "0" would be converted to int, rather than the DatePart() return value being converted to string. So instead of "0" + [int] returning "0[int]" it returns [int].

Therefore...

%{Right("0" + CStr(DatePart("h",Now())), 2)}%%{Right("0" + CStr(DatePart("n",Now())), 2)}%.pdf

...should work. I'll have to wait another 40 minutes to test it unfortunately.

UPDATE: Yep, that was it.
Last Edit: 28 Oct 2015 18:00 by RonMoses. Reason: update
The administrator has disabled public write access.