It won't fail, you just won't have a leading zero on single digit month or day values. If you want to have a leading zero on day or month, just check the length of the day and month strings returned. If they are 1, just add a leading zero. Something like the following:
It won't fail, you just won't have a leading zero on single digit month or day values. If you want to have a leading zero on day or month, just check the length of the day and month strings returned. If they are 1, just add a leading zero. Something like the following:
It won't fail, you just won't have a leading zero on single digit month or day values. If you want to have a leading zero on day or month, just check the length of the day and month strings returned. If they are 1, just add a leading zero. Something like the following:
All Answers
Try this:
Thanks, but won't it fail in case the day or month are single-digit?
For example, 03-03-2012 will result in 201233 , right? I need it to be 20120303
It won't fail, you just won't have a leading zero on single digit month or day values. If you want to have a leading zero on day or month, just check the length of the day and month strings returned. If they are 1, just add a leading zero. Something like the following: