View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default Converting dates

Does VBA have any functions that convert date strings such as M/D/YY,
MM/D/YY, or M/DD/YY to MM/DD/YY format?

For example, if sDate == "1/9/19", then the output should be sDate =
"01/09/19"

The key is that the output date should be in 2-digit month, day and year
format, separated by forward slashes. i.e "MM/DD/YY"

- Robert


Converting a string date to a date will always result the default system date
format unless you specify its NumberFormat as Claus has shown. This has needed
to be the practice since the default date format changed in Vista. My practice
with date cells has been to set the format when designing the worksheet
template so the month portion ALWAYS displays its short format name "Mmm" so
there's no ambiguity; - and this is how string dates are stored as well!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion