How can I convert this date format YYYYMMDD into this date format MM/DD/YY using vbscript.

How can I convert this date format YYYYMMDD into this date format MM/DD/YY using vbscript.


This is comnig from a registry key. Need to put this into a function.


Thanks a bunch
WinPEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sr75Commented:
Here is a script that breaks it as I couldn't get the FormatDate function to work.  
strDate = "19991230"
strYear = left(strDate, 4)
strMonth = left(right(strDate, 4), 2)
strDay = right(strDate, 2)
 
strDate = strMonth & "/" & strDay & "/" & strYear
 
wscript.echo strDate

Open in new window

0
almilyoCommented:
Try

newlyformattedstring = Mid(mystring, 5, 2) & "/" & Mid(mystring, 7, 2) & "/" & Mid(mystring, 1, 4)
0
WinPEAuthor Commented:
genius, that works...

However I get the proper date 2/22/08 but for values are null I get a //

How can I script a scrub of some sort to remove those // entries and just leave them blank, without wiping the entries that have a valid date.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

almilyoCommented:
Taking sr71's much less lazy suggestion...
strDate = "19991230"
strYear = left(strDate, 4)
strMonth = left(right(strDate, 4), 2)
strDay = right(strDate, 2)
 
if isNull(strDate) or strDate="" then 
  strDate = strMonth & "/" & strDay & "/" & strYear
else
  strDate = ""
 
wscript.echo strDate

Open in new window

0
almilyoCommented:
Oops, got that the wrong way round!
if isNull(strDate) or strDate="" then 
  strDate = ""
else
  strDate = strMonth & "/" & strDay & "/" & strYear

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
almilyoCommented:
Glad you got it working...

If you splitting  the points when two people contribute to the answer it's the fairest way to work things out, especially as sr75 took the time to write a much more readable script than I did.
0
sr75Commented:
It really is no big deal.  I am glad that he got what he needed.  Besides, I forgot how to use Mid() and you reminded me how.
0
WinPEAuthor Commented:
Thanks to both of you, I put in the request to split the points... Both were very helpful!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.