Search code examples
excelvbscriptasp-classic

Excel Export Classic Ap Leading Zeros


I'm trying to add the leading zeros to my excel export file but it keeps removing my zeroes.

dteThisDob = rs("dob")
strThisDobYear = year(dteThisDob)
strThisDobMonth = right("0" & month(dteThisDob),2)
strThisDobDay = right("0" & day(dteThisDob),2)
strDob = strThisDobMonth & strThisDobDay & strThisDobYear 

This give me the output in excel 3041975. What I'm looking for is 03041975


Solution

  • You can force Excel to not convert strings to numeric values (and by doing so removing the leading zeros) by prefixing them with a TAB character.

    strDob = Chr(9) & strThisDobMonth & strThisDobDay & strThisDobYear