Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show zeros in StringVar fomula?

Status
Not open for further replies.

staciann

IS-IT--Management
Nov 1, 2006
72
US
Hi. I have an 8 character text field with data that I want to use for a date in a format like this 'MM/DD - MM/DD'

I have the formula {@dateformat}:

Code:
StringVar DF := {tblMeetings.Date}; 
Val (DF [ 1 to 2 ])&"/"&
Val (DF [ 3 to 4 ])&" - "&
Val (DF [ 5 to 6 ])&"/"&
Val (DF [ 7 to 8 ])

that formats my text data like '12/10 - 12/15'
(which is what I want)

My problem is that when I have a value group that contains a single value with a zero in front of it, the zero isn't showing up. Instead of 01/09 - 01/14 I am getting 1/9 - 1/14, even though the data in the record reads 01090114.

Can you please tell me what I am doing wrong or what I have to do to include the zeros?

Thank you so much for your help.
 
You shouldn't be using val(). How does the original string display? Does it already contain the zeros? Please show sample data that reflects the possible variation in the field.

-LB
 
Hi LB -

Some examples of the original data are:

01030105
04090412
06230626
10091013
11261130
12141216

The way I'd like them formatted in my report:

01/03 - 01/05
04/09 - 04/12
06/23 - 06/26
10/09 - 10/13
11/26 - 11/30
12/14 - 12/16
 
Use:

stringvar x := {tblMeetings.Date};
left(x,2)+"/"+mid(x,3,2)+" - "+
mid(x,5,2)+"/"+right(x,2)

-LB
 
That worked great - the only thing now (sorry, I forgot to mention it in my sample data) is the I have some dates that are only one day, not a range so the data would be:

1204
0131

and now they are showing up as
12/04 - /04
01/31 - /31

since right(x,2) then refers back the the last two of the four digits.

I'm sure I can use an if then else statement but I'm not sure how to describe what would be null. How would I say:
if there aren't more than 4 characters then left(x,2)+"/"+right(x,2)?
 
Never mind, I got it to work!
I used:

Code:
stringvar x := {tblMeetings.Date};
if mid(x,5,2)=""
then
left(x,2)+"/"+right(x,2)
else
left(x,2)+"/"+mid(x,3,2)+" - "+
mid(x,5,2)+"/"+right(x,2)

Thanks for all of your help LB!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top