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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display leading zero in the string 2

Status
Not open for further replies.

Cores

Programmer
Oct 17, 2007
92
CA
CRXI
I have a string field in the report which is a date. It can be 040209 for April 2nd, 2009. When the report is exported to CSV format, the field becomes as 40209. I need it as 040209.

I tried to convert it to number or date, but when the rpt. file is exported to CSV format it becomes 40209 instead of 040209.

Can you help me how to work around and make displayed leading zero if the month from 01 to 09?

Thanks
 
You can convert your string field to a number field and then
convert it back to a string with a leading zero

e.g. cstr(tonumber({table.field}), "000000")
 
Thank you, mbunschoten for your reply.

It works excellent in Crystal Reports. But when the file is exported to CSV format, it displays string without leading zero.

Any other ideas to work around this issue?
 
You could create the following formula:

"=" + '"'+ {table.field} + '"'

When you export that to CSV and open in Excel, Excel should assume it's a text field and not crop the zeros.
 
To add to that - If you will use the CSV file for anything other then Excel, that formula will more then likely give you problems.
 
Many thanks mbunschoten,

I will let the client know that it can work only in Excel.

Thanks once again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top